Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace @EnableSwagger2 after update to latest version

I migrated to latest springfox-swagger2 version 2.10.0 but looks like @EnableSwagger2 is deprecated.

What annotation should I use in order to enable Swagger into Spring Boot project? @EnableSwagger2WebMvc?

like image 790
Peter Penzov Avatar asked Jun 23 '20 16:06

Peter Penzov


2 Answers

@EnableSwagger2 was removed in swagger 2.10.x, but from 3.x.x it is there again.

@EnableSwagger2WebMvc is deprecated in 3.0.0+

Funny but true :)


Optionally you can use following dependency with Spring 5 MVC

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

and

  • remove explicit dependencies on springfox-swagger2
  • remove the @EnableSwagger2 annotations
  • add the springfox-boot-starter dependency

see: https://github.com/springfox/springfox

like image 101
vaquar khan Avatar answered Nov 17 '22 16:11

vaquar khan


@Configuration
@EnableSwagger2WebMvc
@Import({SpringDataRestConfiguration.class, BeanValidatorPluginsConfiguration.class})
public class ApplicationSwaggerConfig {

    @Bean
    public Docket schoolApi() {
        return new Docket(DocumentationType.SWAGGER_2).
                select().
                apis(RequestHandlerSelectors.basePackage("com.example.SampleProject")).
                paths(PathSelectors.any()).
                build();
    }

For the other case pertaining to spring security checks, you can make your securityconfiguration class to extend WebsecurityConfigurerAdapter and then you can implement below method -

 @Override public void configure(WebSecurity web) throws Exception {
      web.ignoring().antMatchers( "/v2/api-docs", "/swagger-resources/**", "/configuration/ui","/configuration/security", "/swagger-ui.html");
      
      }

This should help I guess

like image 5
Tushar Mahajan Avatar answered Nov 17 '22 14:11

Tushar Mahajan