gpt4 book ai didi

java - 找不到 Spring Rest 文档生成的内容

转载 作者:行者123 更新时间:2023-11-29 04:37:48 26 4
gpt4 key购买 nike

我正在使用 Spring REST Docs 为我们的 API 生成文档。我已将教程中的所有内容添加到 build.gradle http://docs.spring.io/spring-restdocs/docs/current/reference/html5/

ext {
snippetsDir = file('build/generated-snippets')
}

test {
outputs.dir snippetsDir
}

asciidoctor {
attributes 'snippets': snippetsDir
inputs.dir snippetsDir
outputDir "build/asciidoc"
dependsOn test
sourceDir 'src/main/asciidoc'
}

jar {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}

在我执行 gradle build 之后,我可以看到在 build/asciidoc 目录中生成了文件,也在 build/generated-snippets 中生成了文件。

但是当我从 IDEA gradle task bootRun 运行并尝试访问 localhost:8080/docs/index.html 时,我找不到 404。只是为了测试,我试着放了一些resources/static 目录下的 index.html 文件,然后执行 bootRun 就可以访问 localhost:8080/index.html 之后的文件。

如果我打开我的 .jar 文件,我可以在目录 BOOT-INF/classes/static/docs 下看到静态文件,所以它们被打包到 jar 中。

也许有人有同样的问题?

最佳答案

您需要做两件事,以便在使用 bootRun 时提供文档。第一种是将生成的文档复制到 bootRun 使用的类路径中的某个位置:

task copyRestDocs(type: Copy) {
dependsOn asciidoctor
from "${asciidoctor.outputDir}/html5"
into "${sourceSets.main.output.resourcesDir}/static/docs"
}

请注意,这个新任务依赖于 asciidoctor 任务。这确保文档在复制之前已经生成。

其次,bootRun 任务必须依赖于新的copyRestDocs 任务:

bootRun {
dependsOn copyRestDocs
}

关于java - 找不到 Spring Rest 文档生成的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40511810/

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