Search code examples
javaspring-bootgradleswaggerspringdoc-openapi-ui

Springdoc Whitelabel Error Page with Spring V3


I'm trying to get swagger to run in my spring boot project. I'm currently using the spring verion 3.1.9. I looked up so many guides that told me to just add implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0" to my build.gradle file and then everything works! Wrong! It doesn't. I get this White label error page every time:white label error page

  • I tried every URL.
  • I configured springdoc in the build.gradle with some custom urls.
  • I tried it with the old swagger dependencies

What I haven't tried is Spring-Security. But I don't want/need to use it.


Solution

  • I don't know your configuration.

    Let me give you a sample configuration which is working as expected for me

    plugins {
        id 'java'
        id 'org.springframework.boot' version '3.2.0'
        id 'io.spring.dependency-management' version '1.1.4'
    }
       dependencies {
    //other dependencies
     implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
    }
    

    Swagger Configuration Class

    @Configuration
    public class SwaggerConfig {
    
        @Bean
        public OpenAPI myOpenAPI() {
            return new OpenAPI();
        }
    
    
    }
    

    In Application Properites

    springdoc.api-docs.groups.enabled=true
    springdoc.swagger-ui.operations-sorter=method
    springdoc.swagger-ui.disable-swagger-default-url=true
    springdoc.writer-with-default-pretty-printer=true
    springdoc.default-produces-media-type=application/json
    springdoc.override-with-generic-response=true
    

    Below property may be used when you need to proxy

    server.forward-headers-strategy=framework
    

    I am able to see swagger is loading in below URL : http://localhost:8080/swagger-ui/index.html

    enter image description here