2016-10-20 26 views
2

我想用Swagger用戶界面的API文檔,這是使用Spring引導框架開發的。在com.testApp包Swagger用戶界面的春季引導給空頁

@Path("/resources") 
@Api(value = "Test resource", produces = "application/json") 
public class MyResource { 

@Autowired 
public SomeClass someclass; 

/** 
* 
* @param uriInfo 
* @return 
* @throws PlatformException 
*/ 
@ApiOperation(value = "Gets a hello resource. World Version 1 (version in Accept Header)", response = String.class) 
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "Hello resource found"), 
    @ApiResponse(code = 404, message = "Hello resource not found") 
}) 

@GET 
@Produces({ MediaType.APPLICATION_JSON }) 
public String loadResouces(@Context UriInfo uriInfo) { 
    //method defination 
} 

此服務

1)在POM依賴

<dependency> 
     <groupId>io.springfox</groupId> 
     <artifactId>springfox-swagger2</artifactId> 
     <version>${springfox-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>io.swagger</groupId> 
     <artifactId>swagger-core</artifactId> 
     <version>${swagger-core-version}</version> 
    </dependency> 




<properties> 

    <springfox-version>2.5.0</springfox-version> 
    <swagger-core-version>1.5.10</swagger-core-version> 

</properties> 

2)案卷配置

@ComponentScan(basePackages = {"com.testApp.*"}) 
@Configuration 
@EnableSwagger2 
public class Application { 

@Bean 
    public Docket api() { 

     return new Docket(DocumentationType.SWAGGER_2) 
       .select().apis(
         RequestHandlerSelectors.any()) 
         .paths(PathSelectors.any())        
         .build(); 

    } 


public static void main(String[] args) { 
    SpringApplication.run(Application.class, args); 
} 

3)資源配置在端口9001上運行。每當打本地主機:8080/swagger-ui.html。它返回一個swagger-ui的空白頁面。我已經嘗試了像主機,路徑映射等Docket的一些屬性,但我無法使用此生成文檔。

回答