0

I'm trying to integrate springfox in to my existing sprint web application I configured the springfox the web app is starting correctly but the api doc is not getting generated

here is the springfox configuration class

@EnableSwagger2 //Loads the spring beans required by the framework
public class SwaggerConfig {

  @Bean
  public Docket swaggerSpringMvcPlugin() {

    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .paths(PathSelectors.any())
            .build()
            .apiInfo(apiInfo());
  }
}

here is the bean creation

 <bean id="config" class="com.myApp.general.SwaggerConfig"/>

following is the controller

@Controller
public class MyController {

    @ApiOperation(value = "Gets architecture services",
        notes = "",
        produces = "application/json")
    @RequestMapping(value = "v1/users", method = RequestMethod.GET)
    @ResponseBody
    public Object users(HttpServletResponse response) {
         //method implementation
    }
}

when i try to get the api doc it just returns a 404. can someone help me on this

madu
  • 344
  • 3
  • 14

1 Answers1

0

it may be a late answer..but should help people still looking/searching

anyway the below answer should work . for html the ui.html handler is needed and for others webjars/** is needed

uri.startsWith("/swagger")|| uri.startsWith("/webjars")||uri.startsWith("/v2/api-docs");

if you have filter-chain to access-specific url's ,be sure to omit any filter cheking similar to above code

@Component
public class SwaggerConfiguration extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

       registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

}....

adding above code makes your spring application to look into the folders for swagger-ui files. if you already have a resource handler..donot forget to include these there.In this case no need to write a special resource handler

Fryder
  • 413
  • 2
  • 7
  • 21