swagger 在apache CXF 中的使用——JAX-RS Swagger2Feature
The CXF Swagger2Feature allows you to generate Swagger 2.0 documents from JAX-RS service endpoints with a simple configuration.
见:http://cxf.apache.org/docs/swagger2feature.html JAX-RS Swagger2Feature Demo
================= The demo shows a basic usage of Swagger 2.0 API documentation with REST based Web Services using
JAX-RS 2.0 (JSR-339). Swagger UI is available at: http://localhost:9000/ Building and running the demo using Maven
--------------------------------------- From the base directory of this sample (i.e., where this README file is
located), the Maven pom.xml file can be used to build and run the demo. Using either UNIX or Windows: mvn install
mvn -Pserver (from one command line window) After the service is started, the Swagger API documents in JSON and YAML
are available at http://localhost:9000/swagger.json
http://localhost:9000/swagger.yaml To view the Swagger document using Swagger-UI, use your Browser to
open the Swagger-UI page at http://localhost:9000/api-docs?url=/swagger.json or http://localhost:9000/api-docs?url=/swagger.yaml or access it from the CXF Services page: http://localhost:9000/services
and follow a Swagger link.
例子在:https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Sample.java
示意代码:
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; @Path("/sample")
@Api(value = "/sample", description = "Sample JAX-RS service with Swagger documentation")
public class Sample {
private Map<String, Item> items; public Sample() {
items = Collections.synchronizedMap(new TreeMap<String, Item>(String.CASE_INSENSITIVE_ORDER));
items.put("Item 1", new Item("Item 1", "Value 1"));
items.put("Item 2", new Item("Item 2", "Value 2"));
} @Produces({ MediaType.APPLICATION_JSON })
@GET
@ApiOperation(
value = "Get operation with Response and @Default value",
notes = "Get operation with Response and @Default value",
response = Item.class,
responseContainer = "List"
)
public Response getItems(
@ApiParam(value = "Page to fetch", required = true) @QueryParam("page") @DefaultValue("1") int page) { return Response.ok(items.values()).build();
}
}
swagger 在apache CXF 中的使用——JAX-RS Swagger2Feature的更多相关文章
- Spring 4 集成Apache CXF开发JAX-RS Web Service
什么是JAX-RS 在JSR-311规范中定义,即Java API for RESTful Web Services,一套Java API,用于开发 RESTful风格的Webservice. 工程概 ...
- Apache CXF实现WebService入门教程(附完整源码)
Apache CXF实现WebService非常简单实用,只需要几步就可以实现一个简单的web service. 首先我们需要新建一个maven项目,在pom中添加依赖和jetty作为测试的web s ...
- Apache CXF Webservice入门
1.步骤一览 关于CXF的介绍请移步官网.百科,这里仅供初次使用者入门. 2.步骤详情 2.1.环境准备 apache-cxf-3.0.0.zip下载 jdk1.7.0_51 Eclipse4.3.0 ...
- 在cxf中使用配置避免增加字段导致客户端必须更新、同步实体属性的问题
在使用cxf实现webservice时,经常碰到的问题就是如果在服务端,修改了一个接口的签名实现,如增加一个字段,或者删除一个字段.在这种情况下,在默认的配置中,就会报以下的错误信息: org.apa ...
- Apache CXF自定义拦截器
为什么设计拦截器?1.为了在webservice请求过程中,能动态操作请求和响应数据,CXF设计了拦截器 拦截器分类: 1.按所处的位置分:服务器端拦截器,客户端拦截器. 2.按消息的方向分:入拦截器 ...
- apache CXF wsdl2java工具的使用
cxf的wsdl2java命令和JDK的wsimport命令的区别和使用 JDK提供了一个wsimport.exe的命令,主要是用于将WebService生成客户端代码,然后好调用WebService ...
- 解决Apache CXF 不支持传递java.sql.Timestamp和java.util.HashMap类型问题
在项目中使用Apache开源的Services Framework CXF来发布WebService,CXF能够很简洁与Spring Framework 集成在一起,在发布WebService的过程中 ...
- Apache CXF 103 CXF Basics - partial
本Spike记录中内容,如无特别指出,均引用[1]. 0 引言 0.1 基本的Web服务术语 XML 业界的结构化交换信息表示的事实上的标准. XML namespace是在XML文档中提供唯一的命名 ...
- Apache CXF 102 CXF with REST
前言 续上篇Apache CXF 101,摘抄部分REST概念性知识,以运行实例考察CXF对REST的支持. 目录 1 REST简介 2 工具 3 运行实例 内容 本Spike记录中内容,如无特别指出 ...
随机推荐
- Log Explorer 恢复误删除、更新数据
一.介绍 详细参考:https://blog.csdn.net/jinjazz/article/details/2459692 转自:https://blog.csdn.net/hch27151099 ...
- SSH终端显示中文乱码
出现这种关系,首先想到是因为字符集不匹配导致的.打开SSH客户端,连接到linux虚拟机 在虚拟机中输入#cd /etc#cd sysconfig/ 找到i18ncat i18n 会显示当前的编码类型 ...
- opencv3计算机视觉+Python(四)
使用分水岭和GrabCut算法进行物体分割 用GrabCut算法进行图像分割 在OpenCV中,实现了grabcut分割算法,该算法可以方便的分割出前景图像,操作简单,而且分割的效果很好.算法的原理参 ...
- spring 项目tomcat 8.0.2 发布报错:Could not initialize class org.hibernate.validator.engine.ConfigurationImpl
tomcat 8 项目发布遇到的错 [ERROR] -- ::, org.springframework.web.servlet.DispatcherServlet - Context initial ...
- CentOS7更改网卡名称为eth0
#!/bin/bash # Author: fansik # Date: 2017年 09月 19日 星期二 :: CST sed -i 's@rhgb@rhgb net.ifnames=0@g' / ...
- iOS 视频全屏功能 学习
项目中,也写过类似"视频全屏"的功能, 前一阵子读到今日头条 的一篇技术文章,详细介绍三种旋转方法差异优劣最终择取.文章从技术角度看写的非常好,从用户角度看,也用过多家有视频功能的 ...
- java 图片Base64字符串转图片二进制数组
public static byte[] base64ToImgByteArray(String base64) throws IOException{ sun.misc.BASE64Decoder ...
- webAPI支持跨域
问题描述: 添加引用:右键项目→添加nuget包 在:App_Start/WebApiConfig.Register中添加如下一句话 //跨域配置 config.EnableCors(new Enab ...
- qnx 黑莓系统
qnx 黑莓图形系统框架 http://www.360doc.com/content/07/0807/10/38907_658192.shtml http://blog.csdn.net/keyboa ...
- CSS3 3D旋转下拉菜单
在线演示 本地下载