2017-05-31 4 views
1

i Prahlerei bin mit mit Spring MVC, die pom.xmlSwagger mit Spring MVC in der Dokumentation der Dienste nicht zu erzeugen

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

und im Frühjahr configuration.xml

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

ich benutze auch Java-basierte

Konfiguration
@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(); 
    } 
} 

im Controller verwenden i

@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 ich hinzugefügt springfox.documentation.swagger.v2.path=/api-docs. , dass alle Angaben i Dokumentation zu generieren verwendet die URL mit http://localhost:8080/admin-api/admin/api-docs, tut es Dokumentation für die Endpunkte

{ 
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" 
} 

Antwort

0

Gelöst erzeugen. nach Fehl um viele Dinge, die ich die Lösung gefunden, änderte ich die Methode Docket api()

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

i PathSelectors.regex("/api/.*") auf der alten Methode der das Teil denken sein wurde

den Suchprozess der Endpunkte zu beschränken
Verwandte Themen