2017-05-31 85 views
1

我使用招搖着Spring MVC的服務的文檔中,pom.xml招搖着春天MVC不產生

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

,並在春季configuration.xml文件

<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" /> 
<mvc:resources mapping="/webjars/**" 
    location="classpath:/META-INF/resources/webjars/" /> 

也是我使用基於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(); 
    } 
} 

在控制器我使用

@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) { 

application.propeties我加了springfox.documentation.swagger.v2.path=/api-docs。 即我用於生成使用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" 
} 

回答

0

文檔。之後各地的許多東西,小姐,我找到了解決辦法,我改變了方法Docket api()

@Bean 
public Docket api() { 
    return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()) 
      .paths(PathSelectors.any()).build().apiInfo(apiInfo()); 
} 

我覺得老辦法的部分PathSelectors.regex("/api/.*")被限制的結束點的查找過程