2016-08-25 90 views
1

我有spring-mvc應用程序,我在其中嵌入了RestAPI。所有工作正常我的休息API映射/rest/*網址。當我添加SwaggerConfig時,他開始看到我的控制器,但是當我在swagger-ui(gui form來簡化消費者與api的交互)中試用它時,我找不到404。正因爲如此嘗試過了上 enter image description here 這並不在合法的URL如何在spring-mvc中設置springfox的主機url(更確切地說springfox-swagger2)?

http://localhost:8080/ProductCatalog/rest/branch?id=1 

雖然SwaggerConfig是在正確的URL映射做要求,因爲我得到這個GUI表示當寫

http://localhost:8080/ProductCatalog/rest/swagger-ui.html 

有一個主部分應用程序在根URL(這不是我工作的一部分)我的部分映射在/rest/* 我怎樣才能在/rest/*上更改這個「試試看」url? 我SwaggerConfig

@Configuration 
@EnableSwagger2 
public class SwaggerConfig { 

    @Bean 
    public Docket pscApi() { 
     return new Docket(DocumentationType.SWAGGER_2) 
       //.groupName("PSC"); 
       .apiInfo(apiInfo()) 
       .select() 
       .apis(RequestHandlerSelectors.basePackage("restService.com.websystique.springmvc")) 
       .paths(PathSelectors.any()) 
       .build(); 
     //PathSelectors.regex("/api/.*") 
    } 

    private ApiInfo apiInfo() { 
     return new ApiInfoBuilder() 
       .title("RestApiOfPSC") 
       .description("REST API for PSC.") 
       .build(); 
    } 
} 

,我指定這也

@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/"); 
    } 

對不起我的英文不好,並在此先感謝

回答

2

我知道如何做到這一點。

docket.pathMapping("/rest"); 

有時你NEAD在你的文案豆通過另一種方式 改變它寫docket.host("your host url"); 更準確地讀我的問題 https://github.com/springfox/springfox/issues/1468

,並經過參考#issue1050了。

相關問題