gpt4 book ai didi

kotlin - 如何使用Spring Rest文档可视化index.html页面

转载 作者:行者123 更新时间:2023-12-02 12:58:42 25 4
gpt4 key购买 nike

我基本上开始使用spring rest docs来生成我的rest服务的文档。问题是我不知道如何从应用程序中可视化文档。我很想在http://localhost:8080/docs/index.html中查看结果。但是,当我打开此网址时,我看到了问题:
白标错误页面
此应用程序没有针对/ error的显式映射,因此您将其视为后备。

2019年5月22日星期三22:36:46 COT
发生意外错误(类型=未找到,状态= 404)。
无可用讯息

我已逐步使用nex教程:https://spring.io/guides/gs/testing-restdocs/。我能够按照所有步骤进行操作,现在在我的项目中有摘要:

enter image description here

并且还在以下路径中创建了index.html页面:target / generation-docs / index.html:

enter image description here

在我的pom.xml中,添加了下一个插件:

           <plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<sourceDocumentName>index.adoc</sourceDocumentName>
<backend>html</backend>
<attributes>
<snippets>${project.build.directory}/snippets</snippets>
</attributes>
</configuration>
</execution>
</executions>
</plugin>

最后,我在下一个类中运行我的应用程序:
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
@EnableAutoConfiguration
@ComponentScan(
basePackages = [
"com.espn.csemobile.espnapp",
"com.espn.personalization"]
)
open class SportscenterProductApi

fun main(args: Array<String>) {
val app = SpringApplication(SportscenterProductApi::class.java)
app.setBannerMode(Mode.LOG)
app.setLogStartupInfo(true)
app.run(*args)
}

有任何想法吗?

最佳答案

作为described in the documentation,您需要配置构建以将生成的HTML复制到将其打包到应用程序中的位置。

pom.xml的配置之后,将以下插件配置添加到asciidoctor-maven-plugin:

<plugin> 
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

这样应该可以在 http://localhost:8080/docs/index.html上找到该文档。

关于kotlin - 如何使用Spring Rest文档可视化index.html页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56267924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com