为cxf服务加上wadl描述信息
我们在开发cxf rest服务的时候,往往需要为每个服务添加描述文档,以前我们可能是将描述文档用word或者excel记录,现在介绍一种通过cxf-rt-rs-service-description自动生成wadl描述文档的方法。
1. 首先我们在项目中引入cxf-rt-rs-service-description包,通过maven方式构建
<
dependency
>
<
groupId
>org.apache.cxf</
groupId
>
<
artifactId
>cxf-rt-rs-service-description</
artifactId
>
<
version
>3.0.0-milestone1</
version
>
</
dependency
>
2. 在服务中添加描述信息
@GET
@Path("/reses/{resId}/{userId}")
@Produces(MediaType.APPLICATION_JSON)
@Description(value = "展示资源详情", target = DocTarget.METHOD)
public ReturnMsg<ResourceDTO> showRes(@PathParam("resId") String resId, @PathParam("userId") String userId);
3. 启动服务,访问http://192.9.8.8:9080/reslib/api/?_wadl出现下面内容表示成功配置。
参考文档:http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-WADLAutoGenerationatRuntime