Home > Software design >  Spring springdoc-openapi : swagger-ui/index.html cannot be found status=404
Spring springdoc-openapi : swagger-ui/index.html cannot be found status=404

Time:05-20

I've a spring boot application (2.5.6) with a dependency on springdoc-openapi. However, launching swagger-ui (http://localhost:8080/v1/swagger-ui/index.html) doesn't work. The debug logs are indicating that index.html is not present. What could be the reason that index.html is not found ?

enter image description here

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

application.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"

enter image description here

CodePudding user response:

Try swagger-ui.html instead of swagger-ui/index.html. In 60% of the cases swagger-ui.html redirects to its real location.

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

CodePudding user response:

I found the cause of the problem. The context-path was not set in application.yaml.

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

After adding servlet : context-path, swagger-ui is rendered

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