Java 春季MVC招摇过市问题
我正在使用Java 春季MVC招摇过市问题,java,spring-mvc,swagger,swagger-ui,swagger-2.0,Java,Spring Mvc,Swagger,Swagger Ui,Swagger 2.0,我正在使用springmvc+Swaggerversion1.0.2集成。我面临着RESTDocsAPI上出现重复API的问题。不知道为什么 但是我调试了这个问题,我添加了以下链接,并根据这个链接添加了以下代码 @Configuration @EnableSwagger public class SwaggerConfig { private SpringSwaggerConfig springSwaggerConfig; @Autowired public void
springmvc+Swagger
version1.0.2
集成。我面临着RESTDocsAPI上出现重复API的问题。不知道为什么
但是我调试了这个问题,我添加了以下链接,并根据这个链接添加了以下代码
@Configuration
@EnableSwagger
public class SwaggerConfig {
private SpringSwaggerConfig springSwaggerConfig;
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
this.springSwaggerConfig = springSwaggerConfig;
}
@Bean
// Don't forget the @Bean annotation
public SwaggerSpringMvcPlugin customImplementation() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(
apiInfo()).includePatterns(".*");
}
private ApiInfo apiInfo() {
return new ApiInfo("API", "API",
null, "test@yahoo.com",
"License", "http://test.license");
}
}
但当我添加时,从那以后我看到相同的API被加载了两次,如下所示
Mapped "{[/api/student],methods=[POST],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.lang.String> com.test.StudentController.getStudentDetails(com.test.model.StudentDetails) throws java.lang.Exception
Mapped "{[/api/student],methods=[POST],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.lang.String> com.test.StudentController.getStudentDetails(com.test.model.StudentDetails)
throws java.lang.Exception
..................
将“{[/api/student],methods=[POST],products=[application/json]}”映射到public org.springframework.http.responseEntitycom.test.StudentController.getStudentDetails(com.test.model.StudentDetails)抛出java.lang.Exception
将“{[/api/student],methods=[POST],products=[application/json]}”映射到public org.springframework.http.ResponseEntity com.test.StudentController.getStudentDetails(com.test.model.StudentDetails)
抛出java.lang.Exception
..................
如何防止两次加载bean?我能够解决这个问题。问题与您的
applicationContext.xml
或mvc rest.xml
等无关,您的应用程序代码根本不应该使用@EnableSpring
,然后它就工作了。甚至这个链接也表明了同样的情况