Search code examples
springspring-bootswagger-uiopenapispringdoc

404 error on Swagger UI with Spring (springdoc-openapi configuration)


I am adding swagger UI to my Spring boot application. When I try to access the swagger-ui.html. I get the 404 error.

Config class :

@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("JOYAS-STOCK API Docs")
                        .description("JOYAS-STOCK REST API documentation")
                        .version("v1.0.0"));
    }
}

appliaction.properties :

#swagger-ui config
springdoc.swagger-ui.path=/swagger-ui
springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tagsSorter=alpha

pom.xml :

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

error message : Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

There was an unexpected error (type=Not Found, status=404).

i started with the implementation of the configuration of swagger and apparently it's not working.

click to see screen of the error


Solution

  • Resolved.

    the issue was in the versions, they were not compatible! i was using springdoc-openapi v1 with spring boot 3. which is wrong! with spring boot 3, springdoc-openapi v2 should be used. see documentation : https://springdoc.org/v2/