0

I am using Spring MVC + Swagger version 1.0.2 integration. I am facing issue of duplicates API being seen on the REST docs API. Not sure why?

But I debug the issue, I following link https://dzone.com/articles/documenting-your-spring-api and A 'simple' way to implement Swagger in a Spring MVC application, as per this link I added following code

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

But when I added, since then I see same API is getting loaded twice like below

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
..................

How to prevent loading beans twice ?

Community
  • 1
  • 1

1 Answers1

0

I was able to solve this issue. The issue was nothing to do with your applicationContext.xml or mvc-rest.xml etc, your application code should not be using @EnableSpring at all, then it worked. Even this link https://github.com/springfox/springfox/issues/565#issuecomment-172956702 also suggests the same.