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 ?

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

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}"
To share my experience because I have just spend more than 1 day to resolve a similar problem.
This can happen if the project contains a configuration class extending WebMvcConfigurationSupport.
To be more precise :
/v3/api-docs route was working/swagger-ui/index.html was throwing a 404 errorAs I said, we had inside the project a configuration class extending WebMvcConfigurationSupport in order to automatically convert lowercase String inside the request to an uppercase Enumeration (How to make enum parameter lowercase in SpringBoot/Swagger?)
In this case, Spring creates first a bean extending WebMvcConfigurationSupport where the addResourceHandlers(ResourceHandlerRegistry) method does nothing (Empty method).
When this configuration class is not present, Spring creates a bean DelegatingWebMvcConfiguration extending WebMvcConfigurationSupport but this class overrides the addResourceHandlers(ResourceHandlerRegistry) method to register all the WebMvcConfigurer beans to the ResourceHandlerRegistry.
So it adds the SwaggerWebMvcConfigurer that manages the route swagger-ui/index.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With