I have a RESTful Spring application with two @Configuration classes and my swagger methods are listed twice.
I have a swagger config
@Configuration
@EnableSwagger // Loads the spring beans required by the framework
public class SwaggerConfig {
private SpringSwaggerConfig springSwaggerConfig;
/**
* Required to autowire SpringSwaggerConfig
* @param springSwaggerConfig spring swagger config
*/
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
this.springSwaggerConfig = springSwaggerConfig;
}
/**
* Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc
* framework - allowing for multiple swagger groups i.e. same code base
* multiple swagger resource listings.
* @return SwaggerSpringMvcPlugin
*/
@Bean
public SwaggerSpringMvcPlugin customImplementation() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
.apiInfo(apiInfo())
.includePatterns(".*myPattern.*")
.useDefaultResponseMessages(false)
.apiVersion("1.1.0");
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo("my Service REST API",
null /*"REST API for my service."*/, null /*"My Apps API terms of service"*/,
null /*"myemail@mycompany.de"*/, null /*"My Apps API Licence Type"*/,
null /*"My Apps API License URL"*/);
return apiInfo;
}
}
And, to solve this issue: Get Request fails for .com email addresses because Spring interpretes it as a extensions, I have a second config:
@Configuration
@EnableWebMvc
public class RestCommonsMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
But now all of my swagger methods are listed twice. If I remove the @EnableWebMvc annotation, they are all listed just once again, but the config does not do anymore what it is expected to do (fix above mentioned bug).
What can I do now?
edit
I tried to extend from WebMvcConfigurationSupport directly, but the problem does not disappear.
@Configuration
public class MyConfiguration extends WebMvcConfigurationSupport {
//@EnableWebMvc
//public class RestCommonsMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}