spring-mvc - 使用应用程序发布 spring-restdocs html 文档

标签 spring-mvc spring-boot documentation spring-restdocs

我有带有 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/

相关文章:

java - Spring Webflux Webclient |内容类型标题设置问题

java - 如何处理来自 Spring Data Rest Resource 的异常?

java - 如何让 Java API Javadocs 出现在 Ubuntu 的 Eclipse 中

Spring MVC 使用表单 :checkbox to bind data

java - Spring Boot如何创建Auto配置类

java - JHipster 按实体字段搜索实体

c# - Doxygen 不会生成指向没有显式类名的方法的链接

java - HTTP 状态 500 - 预期 session 属性 'userObject'

spring - 在 Spring Boot 的 Servlet 配置中添加过滤器

c# - 自动生成文档和继承