[英]Swagger with spring MVC not generating the documentation of the services
i am using swagger with spring mvc, the pom.xml
我正在使用带有spring mvc,
pom.xml
招摇
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
and in spring configuration.xml 并在spring configuration.xml中
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" />
<mvc:resources mapping="/webjars/**"
location="classpath:/META-INF/resources/webjars/" />
also i use java-based configuration 我也使用基于java的配置
@Configuration
@EnableSwagger2
@PropertySource("classpath:application.properties")
public class SwaggerConfig extends WebMvcConfigurerAdapter {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/api/.*")).build().apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title(" Admin Api").description("Admin Api").version("V1")
.termsOfServiceUrl("http://terms-of-services.url").license("LICENSE")
.licenseUrl("http://url-to-license.com").build();
}
}
in the controller i use 在我使用的控制器中
@Controller
@RequestMapping({ "/" })
@Api(value = "product", description = "Products Web Services") // Swagger annotation
public class ProductController {
@ApiOperation(value = "products", nickname = "Get list of all products", response = ProductListResponse.class)
@RequestMapping(value = "/products", method = RequestMethod.GET)
public @ResponseBody ProductListResponse getAllProducts(HttpServletResponse httpServletResponse) {
in application.propeties
i added springfox.documentation.swagger.v2.path=/api-docs
. 在
application.propeties
我添加了springfox.documentation.swagger.v2.path=/api-docs
。 that is all information i used to generate documentation using the url http://localhost:8080/admin-api/admin/api-docs , it doesnt generate documentation for the end points 这是我用来生成文档的所有信息,使用url http:// localhost:8080 / admin-api / admin / api-docs ,它不会为终点生成文档
{
swagger: "2.0",
info: {
description: " Admin Api",
version: "V1",
title: "Admin Api",
termsOfService: "http://terms-of-services.url",
license: {
name: "LICENSE",
url: "http://url-to-license.com"
}
},
host: "localhost:8080",
basePath: "/admin-api/admin"
}
Solved. 解决了。 after miss around many things i found the solution, i changed the method
Docket api()
to be 在我找到解决方案的许多事情之后,我改变了方法
Docket api()
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build().apiInfo(apiInfo());
}
i think the the part PathSelectors.regex("/api/.*")
on the old method was restricting the lookup process of the end points 我认为旧方法上的
PathSelectors.regex("/api/.*")
部分限制了端点的查找过程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.