Swagger无法使用CFX和Spring Boot

时间:2018-07-19 13:07:12

标签: spring-boot jax-rs cxf swagger

我正在尝试使用CXF 3.1.11和Spring Boot 1.5.3生成Swagger文档,但是由于某些原因它无法正常工作

下面是我的pom.xml

<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
  <version>3.1.11</version>
</dependency>
<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
  <version>3.1.11</version>
</dependency>
<dependency>
  <groupId>org.webjars</groupId>
  <artifactId>swagger-ui</artifactId>
  <version>3.10.0</version>
</dependency>

下面是Feature2Swagger bean,其中cxf.path设置为/services/rest

@Configuration
public class FeatureConfig {

   @Value("${cxf.path}")
   private String basePath;

   @Bean("swagger2Feature")
   public Feature swagger2Feature() {

   Swagger2Feature result = new Swagger2Feature();
   result.setTitle("Spring Boot + CXF + Swagger Example");
   result.setDescription("Spring Boot + CXF + Swagger");
   result.setBasePath(this.basePath);
   result.setVersion("v1");
   result.setContact("Meena");
   result.setSchemes(new String[] { "http", "https" });
   result.setScan(true);
   return result;
  }
}

以下是其余服务之一的API

@Path("/hr/v1")
@Api(value = "HR Rest Server", consumes = MediaType.APPLICATION_JSON, 
produces = MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface HrRestService {

  @GET
  @Path("/employee/{id}/")
  @ApiOperation(value = "Finds Employee with Id - (version in URL)")
  @ApiResponses(value = { @ApiResponse(code = 200, message = "Employee found", response = Employee.class),
  @ApiResponse(code = 404, message = "Employee not found") })
  public Employee getEmployee(@PathParam("id") long id);

}

我能够使用上面的REST服务来检索数据。另外,我可以在URL http://localhost:8081/services/rest/?_wadl上看到WADL文档。

但是当我尝试访问URL http://localhost:8081/services/rest/swagger.json时,会得到404 - Page Not Found

有什么建议我想念的吗?

0 个答案:

没有答案