[英]Spring springdoc-openapi : swagger-ui/index.html cannot be found status=404
I've a spring boot application (2.5.6) with a dependency on springdoc-openapi.我有一个依赖于 springdoc-openapi 的 spring boot 应用程序(2.5.6)。 However, launching swagger-ui (http://localhost:8080/v1/swagger-ui/index.html) doesn't work.但是,启动 swagger-ui (http://localhost:8080/v1/swagger-ui/index.html) 不起作用。 The debug logs are indicating that index.html is not present.调试日志表明 index.html 不存在。 What could be the reason that index.html is not found ?找不到 index.html 的原因可能是什么?
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.8</version>
</dependency>
application.yaml应用程序.yaml
springdoc:
swagger-ui:
tagsSorter: alpha
operations-sorter: alpha
doc-expansion: none
disable-swagger-default-url: true
logging:
level:
root: DEBUG
server:
port: 8080
spring:
application:
name: fe-applic-app
api-version: "v1"
Try swagger-ui.html
instead of swagger-ui/index.html
.尝试swagger-ui.html
而不是swagger-ui/index.html
。 In 60% of the cases swagger-ui.html
redirects to its real location.在 60% 的情况下, swagger-ui.html
会重定向到它的真实位置。
http://localhost:8080/v1/swagger-ui.html http://localhost:8080/v3/swagger-ui.html http://localhost:8080/v1/swagger-ui.html http://localhost:8080/v3/swagger-ui.html
I found the cause of the problem.我找到了问题的原因。 The context-path was not set in application.yaml.未在 application.yaml 中设置上下文路径。
http://localhost:8080/ v1 /swagger-ui/index.html http://localhost:8080/ v1 /swagger-ui/index.html
After adding servlet : context-path , swagger-ui is rendered添加servlet : context-path后,渲染 swagger-ui
server:
port: 8080
servlet:
context-path: "/${spring.application.api-version}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.