我有带有 spring-restdocs 的 spring-boot 应用程序,我想在该应用程序中为生成的文档创建端点。使用生成的 html 文档(由 asciidoctor)公开端点的最佳方法是什么?
我可以将 index.html 包含到 jar 文件中,但不知道如何创建将使用该 html 并暴露在外部的端点。此 html 在测试阶段之后和构建 jar 阶段之前生成。
来自官方文档:
您可以将您创建的 HTML 文档发布到静态网站,或者将其打包并从应用程序本身提供。
例如我在“build/asctiidoctor/html5”文件夹中有 index.html 并且想要创建将返回该 index.html 的 Controller 。
最佳答案
根据documentation您可以配置您的构建系统(Maven、Gradle)以将 HTML 作为静态内容打包到 spring-boot jar 中,以便 Spring Boot“自动”提供服务
对于 Gradle 4.6 和 Spring Boot 2.0.0.RELEASE:
bootJar {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}
然后可以通过
'localhost:<your-port>/<your-context-path/docs/index.html
在本地进行验证
关于spring-mvc - 使用应用程序发布 spring-restdocs html 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49558157/