Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 287
user2023141 Avatar asked Jul 25 '26 12:07

user2023141


2 Answers

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}"
like image 78
user2023141 Avatar answered Jul 27 '26 02:07

user2023141


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 :

  • The /v3/api-docs route was working
  • The /swagger-ui/index.html was throwing a 404 error

As 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.

like image 36
Matthieu Saleta Avatar answered Jul 27 '26 02:07

Matthieu Saleta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!