Search code examples
javaspring-bootswagger-uiopenapispringdoc-openapi-ui

Cannot open swagger-ui with the usage of Openapi in Spring Boot 3 (Whitelabel Error Page)


I have an issue to open swagger-ui through Openapi in Spring Boot.

When I try to open this URL http://localhost:8080/swagger-ui.html, I get Whitelabel Error Page

How can I fix the issue?

Here is the dependency defined in pom.xml shown below.

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

Here is the openpi config class shown below.

@Configuration
public class OpenApiConfig {

    @Bean
    public OpenAPI customOpenAPI(@Value("${application-description}") String description,
                                 @Value("${application-version}") String version) {
        return new OpenAPI()
                .info(new Info().title("API")
                        .version(version)
                        .description(description)
                        .license(new License().name("API Licence")));
    }
}

Here is the application.properties file shown below.

springdoc.swagger-ui.path=/swagger-ui.html
application-description=API Description
application-version=1.0

logging.level.org.springframework.web=DEBUG
logging.level.io.springfox=DEBUG

Here is the error shown below when I try to open this URL http://localhost:8080/swagger-ui.html

2023-02-09T08:36:16.593+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : GET "/swagger-ui.html", parameters={}
2023-02-09T08:36:16.594+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
2023-02-09T08:36:16.596+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2023-02-09T08:36:16.596+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2023-02-09T08:36:16.597+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2023-02-09T08:36:16.597+03:00 DEBUG 20184 --- [nio-8080-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)
2023-02-09T08:36:16.599+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, text/html;q=0.8]
2023-02-09T08:36:16.599+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 404

How can I fix the issue?

Here is the repo : Link


Solution

  • You need to use a different dependency for Spring Boot 3:

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
        <version>2.3.0</version>
    </dependency>
    

    Find the current version here.