我有一个带有两个@Configuration类的RESTful Spring应用程序 我的招摇方法被列出两次。
我有一个招摇的配置
@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;
}
}
并且,为了解决这个问题:Get Request fails for .com email addresses because Spring interpretes it as a extensions,我有第二个配置:
@Configuration
@EnableWebMvc
public class RestCommonsMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
但现在我的所有招摇方法都列出了两次。如果我删除@EnableWebMvc注释,它们都会再次列出,但是配置不再执行预期的操作(修复上面提到的错误)。
我现在能做什么?
修改
我试图直接从WebMvcConfigurationSupport扩展,但问题并没有消失。
@Configuration
public class MyConfiguration extends WebMvcConfigurationSupport {
//@EnableWebMvc
//public class RestCommonsMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}