java - Swagger Springfox Configuration Issue -


i have application uses spring mvc handle rest calls, controllers rest controllers , annotated @restcontroller, , controller , methods annotated @requestmapping.

i'm trying add swagger generate documentation existing rest services. i'm trying add 1 test see looks like. i've added springfox , ui libraries, added swagger config classes , bean definitions spring context xml file. can hit swagger-ui.html link, it's not generating documentation @ all. because of sparse documentation, have no idea i'm doing wrong or misconfigured, , googling issue doesn't produce useful.

can provide suggestions of might have done wrong, or alternatively, better documentation i've found far?

i added springfox-swagger2 , associated ui entry pom file, added this: spring file, along 2 new bean definitions these classes:

 @configuration @enableswagger2 public class applicationswaggerconfig {      @bean     public docket api() {         return new docket(documentationtype.swagger_2)                 .select()                 .apis(requesthandlerselectors.any())                 .paths(pathselectors.any())                 .build();     }  }  @enablewebmvc 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/");     }  } 

i've tried defining beans in second class in spring xml, didn't work either. i'm stumped. i've done documentation said do, , it's not working. ideas?

the springfox documentation available here. post appears may need following

    @override     public void addviewcontrollers(viewcontrollerregistry registry) {              registry.addredirectviewcontroller("/documentation/v2/api-docs", "/v2/api-docs?group=restful-api");             registry.addredirectviewcontroller("/documentation/swagger-resources/configuration/ui","/swagger-resources/configuration/ui");             registry.addredirectviewcontroller("/documentation/swagger-resources/configuration/security","/swagger-resources/configuration/security");             registry.addredirectviewcontroller("/documentation/swagger-resources", "/swagger-resources");     }      @override     public void addresourcehandlers(resourcehandlerregistry registry) {              registry                    .addresourcehandler("/documentation/swagger-ui.html**")                    .addresourcelocations("classpath:/meta-inf/resources/swagger-ui.html");             registry                    .addresourcehandler("/documentation/webjars/**")                    .addresourcelocations("classpath:/meta-inf/resources/webjars/");     } 

note: not needed if have spring boot application.

  • make sure you're using latest library version (at time of writing 2.6.0)
  • verify can see swagger service description @ http(s)://your-host/context-path/v2/api-docs

Comments