Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 春季MVC招摇过市问题_Java_Spring Mvc_Swagger_Swagger Ui_Swagger 2.0 - Fatal编程技术网

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
version
1.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
,然后它就工作了。甚至这个链接也表明了同样的情况