I am working on intergrating Springfox 2.2.2 into my Spring MVC project but there are no api-docs generated as I suposse should be. Below some information concerning my configuration.
I have provided following dependencies (together with additional libraries as fasterxml, webjars, correct versions of spring are used etc.)
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>
The Springfox is configured as follows:
package com.exemplarypackage.config;
@Configuration
@EnableSwagger2
@EnableWebMvc
@ComponentScan("com.exemplarypackage.controller")
public class SwaggerConfig extends WebMvcConfigurerAdapter{
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo(
"My Project's REST API",
"This is a description of your API.",
"API TOS",
"url",
"[email protected]",
"API License",
"API License URL");
return apiInfo;
}
@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/");
}
}
The exemplary controller is presented below:
package com.exemplarypackage.controller;
@Api(value = "test class for springfox")
@Controller
public class TestController {
@ApiOperation(value = "Returns test details")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successful retrieval", response = Test.class),
@ApiResponse(code = 404, message = "Test does not exist"),
@ApiResponse(code = 500, message = "Internal server error")}
)
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(Locale locale, Model model) {
logger.info("TEST");
return "test";
}
}
With the above settings, when I executed the url: localserver:8080/myApp/swagger-ui there was almost nothing to display but there was no error message.
Then, I added to the src/main/resources/META-INF the content that I found in spring-fox-swagger-ui-2.2.2.jar (I unzipped it and pasted to given folder). Now, when I go to localserver:8080/myApp/swagger-ui all green graphics are displayed but no api docs. I noticed in server logs that swagger-ui looks for swagger-resources endpoints but it gets 404 then. When I go through the server logs, I saw that no such endpoints have been created as: swagger-resources, v2/api-docs etc. However, I noticed that the classes are filtered for swagger annotations... There is a springfox.js file in META-INF/resources/webjars/springfox-swagger-ui folder where the swagger-resorces endpoint is contained - maybe it should be switched to different name?
I have no idea how to make it work... Should I declare somehow those endpoints or should they be automatatically created? Maybe I am just missing somthing small but I am fighting with the problem for the last days and can't figure out what else should be configured to make it work.
localserver:8080/myApp/v2/api-docs
? – Dilip Krishnan