0

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);
    }

}
Community
  • 1
  • 1
Nina
  • 681
  • 1
  • 10
  • 27
  • Just use the first `@configuration` class without the `@EnableWebMvc`. – M. Deinum Aug 20 '15 at 17:58
  • Without @EnableWebMvc I get the above mentioned error, so I can't remove it. – Nina Oct 20 '15 at 13:27
  • Extending `WebMvcConfigurationSupport` is the same as adding `@EnableWebMvc` so that will yield the same result. Also make sure you are loading the configuration only once and that it is loaded by the `DispatcherServlet` only and not that you are scanning the same classes multiple times (`@Configuration` classes are also detected by component scanning). – M. Deinum Oct 20 '15 at 13:35

0 Answers0