繁体   English   中英

Spring springdoc-openapi:swagger-ui/index.html 找不到状态=404

[英]Spring springdoc-openapi : swagger-ui/index.html cannot be found status=404

我有一个依赖于 springdoc-openapi 的 spring boot 应用程序(2.5.6)。 但是,启动 swagger-ui (http://localhost:8080/v1/swagger-ui/index.html) 不起作用。 调试日志表明 index.html 不存在。 找不到 index.html 的原因可能是什么?

在此处输入图像描述

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.8</version>
</dependency>

应用程序.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"

在此处输入图像描述

尝试swagger-ui.html而不是swagger-ui/index.html 在 60% 的情况下, swagger-ui.html会重定向到它的真实位置。

http://localhost:8080/v1/swagger-ui.html http://localhost:8080/v3/swagger-ui.html

我找到了问题的原因。 未在 application.yaml 中设置上下文路径。

http://localhost:8080/ v1 /swagger-ui/index.html

添加servlet : context-path后,渲染 swagger-ui

server:
  port: 8080
  servlet:
    context-path: "/${spring.application.api-version}"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM