Search code examples
springspring-bootspring-securityswaggerswagger-ui

spring boot 2.5.6 without spring security and security config upgraded to spring boot 3 making swagger not working


When trying to upgrade my spring boot project from 2.5.6 to 3.2.5 swagger UI stops working. In version 2.5.6, I do not have spring security nor security config. I have only SwaggerConfig :

@Configuration
public class SwaggerConfig {

    @Value("${spring.application.name}")
    private String applicationId;

     @Value("${spring.application.description}")
    private String description;

     @Value("${spring.application.version}")
    private String version;

    @Value("${app.env}")
    private String env;

     @Bean
    public OpenAPI openAPI() {
             return new OpenAPI()
                     .info(apiInfo())
                   .components(new Components());
    }

    private Info apiInfo(){
        Info info= new Info();
            info.setTitle(env + " - " + applicationId);
            info.setDescription(description);
            info.version(version);
        return info;
    }
}

Is it necessary to add spring security after upgrading to spring boot 3.2.5, or should i change my SwaggerConfig? Or is the problem somewhere else?

Thank you very much and have a good day.


Solution

  • It seems like the compatibility issue in your case might be due to SpringFox not being updated since July 2020, and its latest version, 3.0.0, only supports Spring Boot 2.0.0.

    You might need to switch to SpringDoc, which is compatible with Spring Boot 3.0.0 and onwards.

    This migration guide will be a great help to you

    Gradle

    implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.2.0'
    

    Maven

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

    SwaggerConfig

    @Configuration
    public class SwaggerConfig {
    
     @Bean
     public OpenAPI openAPI() {
      return new OpenAPI()
       .info(new Info()
        .title("Title of the API")
        .description("Description of the API.")
        .version("Version of the API"));
     }
    }
    

    References Docs

    1. Spring boot 3 doesn't work with springfox 3.0
    2. https://github.com/springfox/springfox/issues/4017
    3. https://www.baeldung.com/spring-rest-openapi-documentation

    have a nice day - kevin