1. 引入cxf的jar包
pom文件里面直接增加依赖
< dependency>
<groupId > junit</ groupId>
<artifactId > junit</ artifactId>
<version >4.11 </version >
<scope >test </scope >
</dependency >
<dependency >
<groupId >org.springframework </groupId >
<artifactId >spring- webmvc</ artifactId>
<version >4.0.0.RELEASE </version >
</dependency >
<dependency >
<groupId >org.apache.cxf </groupId >
<artifactId > apache-cxf </artifactId >
<version >2.4.3</version >
<type > pom</ type>
</dependency >

2. 配置web.xml文件
<? xml version= "1.0" encoding= "UTF-8" ?>
< web-app xmlns= "http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation= "http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version= "3.1" >

< display-name >Archetype Created Web Application </display-name >
< context-param >
<param-name >contextConfigLocation </param-name >
<param-value >classpath:config/spring/metadataWebService-spring.xml </param-value >
</context-param >
<listener >
<listener-class >org.springframework.web.context.ContextLoaderListener </listener-class >
</listener >
<servlet >
<servlet-name >CXFServlet </servlet-name >
<servlet-class >org.apache.cxf.transport.servlet.CXFServlet </servlet-class >
</servlet >
<servlet-mapping >
<servlet-name >CXFServlet </servlet-name >
<url-pattern >/services/* </url-pattern >
</servlet-mapping >
<filter >
<filter-name >encodingFilter </filter-name >
< filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class >
<init-param >
<param-name >encoding </param-name >
<param-value >UTF-8 </param-value >
</init-param >
<init-param >
<param-name >forceEncoding </param-name >
<param-value >true </param-value >
</init-param >
</filter >
<filter-mapping >
<filter-name >encodingFilter </filter-name >
<url-pattern >/* </url-pattern >
</filter-mapping >
</ web-app>

3. 配置cxf.xml文件
<? xml version= "1.0" encoding= "UTF-8" ?>
< beans xmlns= "http://www.springframework.org/schema/beans"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws= "http://cxf.apache.org/jaxws"
xmlns:context= "http://www.springframework.org/schema/context"
xmlns:jaxrs= "http://cxf.apache.org/jaxrs"
xsi:schemaLocation= "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd" >

<import resource = "classpath:META-INF/cxf/cxf.xml" />
<import resource = "classpath:META-INF/cxf/cxf-servlet.xml" />
<context:annotation-config />

<!-- 扫描开启服务的包路径,在base-package下面所有的类都会扫描 -->
< context:component-scan base-package= "com.sigmatrix.ws" />

<!-- REST 服务开放 id和address都是唯一的,在这里开通了两个id,ref可以有多个,bean的名称为接口实现类第一个字母小写-->
<jaxrs:server id = "metadata" address= "/metadata" >
<jaxrs:serviceBeans >
<ref bean = "metadataRestImpl"/>
</jaxrs:serviceBeans >
</jaxrs:server >
<jaxrs:server id = "dictionary" address= "/dictionary" >
<jaxrs:serviceBeans >
<ref bean = "dictionaryRestImpl"/>
</jaxrs:serviceBeans >
</jaxrs:server >
</ beans>

4. 要开放的接口加上cxf服务的注解
接口类:
public interface IMetadataRest {
/**
* 查询所有字典字典项信息
* @return
*/
@POST
@Path( "findAllDictionary")
public abstract String findAllDictionary();
}
接口实现类:
//加入注解
@Component
public class MetadataRestImpl implements IMetadataRest {
@Override
public String findAllDictionary () {
return "Hello World";
}
}

5. 部署到tomcat启动即可,测试访问 ip:端口号//项目名称/services/

通过CXF,开发rest协议接口的更多相关文章

  1. JMeter5.1开发Java协议接口脚本【待完成】

    JMeter5.1开发Java协议接口脚本

  2. 通过CXF,开发soap协议接口

    1. 引入cxf的jar包 pom文件里面直接增加依赖 < dependency> <groupId > junit</ groupId> <artifact ...

  3. (二)使用CXF开发WebService服务器端接口

    CXF作为java领域主流的WebService实现框架,Java程序员有必要掌握它. CXF主页:http://cxf.apache.org/ 简介:百度百科 今天的话,主要是用CXF来开发下Web ...

  4. JMeter5.1开发TCP协议接口脚本

    最简单的方法,就是找开发给报文,直接复制到tcp取样器中,将需要变化的值做参数化就可以了.(xml报文要去掉回车换行) 下面是一个通讯头定义 通讯头56个字节(1个字符一个字节) 3 + 9 + 9 ...

  5. LoadRunner开发ftp协议接口之上传文件脚本

    Action() { //建立一个ftp对象 FTP ftp1=0; //建立FTP连接并登录 ftp_logon_ex(&ftp1,"ftpLogon", "U ...

  6. LoadRunner开发http协议接口之form表单脚本

    loadrunner传form表单,用web_submit_data函数. Action() { // lr_start_transaction("hp_homepage"); / ...

  7. JMeter5.1开发http协议接口之form表单脚本

    get请求--jmeter:form表单 下载文件 响应结果 post请求--jmeter:form表单 登录请求 响应结果 post请求--jmeter:form表单中传token 请求(token ...

  8. JMeter5.1开发http协议接口之json

    信息头指定是json 传json 包含传token,请参考:https://www.cnblogs.com/uncleyong/p/11668665.html

  9. JMeter5.1开发SMTP协议接口脚本

    jmeter可以测试发邮件和读取邮件. 发送邮件 上图部分解释: Server:邮件发送服务 Port:发邮件端口,不加密25,加密465,如果是465端口,Security settings 需要选 ...

随机推荐

  1. centos 7编译安装apache

    1.安装工具和依赖包 yum install unzipyum -y install gcc gcc-c++ 2.创建软件安装目录mkdir /usr/local/{apr,apr-util,apr- ...

  2. 设计模式之第7章-外观模式(Java实现)

    设计模式之第7章-外观模式(Java实现) “鱼哥,知道怎么把大象装进冰箱里面么?”(作者按:这么简单的问题还想考我,早了几百年吧.)“把大象装进冰箱里,一共需要三步:第一步,把冰箱门打开:第二步,把 ...

  3. 九度oj 1006 ZOJ问题 2010年浙江大学计算机及软件工程研究生机试真题

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:16244 解决:2742 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC.是 ...

  4. 通过IntelliJ IDEA忽略掉不需要提交到github的文件

    现如今,开源项目越来越多,存储容器主要有github,国内的码云.开源贡献也是衡量一个开发者是否具有足够的包容能力.技术能力的重要标准. 有些开发者没注意到这些,好心提交开源项目,配置文件也提交上去, ...

  5. c++字符前面的L和_T

    字符串前面加L表示该字符串是Unicode字符串._T是一个宏,如果项目使用了Unicode字符集(定义了UNICODE宏),则自动在字符串前面加上L,否则字符串不变.因此,Visual C++里边定 ...

  6. 巧用CheckedTextView完成自定义radiobutton的listview

    因为要用自定义图片的radiobutton的listview,最开始想自己重新写BaseAdapter,重新定义BaseAdapter中的每个list的item.总之android提供了太多方便的控件 ...

  7. js 递归树结构数据查找父级

    1.json树数据查找所有父级--完成 json:树结构数据 var arrData = [{ "label": "中国", "City": ...

  8. js扩展

    http://www.css88.com/doc/underscore/#findWhere

  9. Asp.Net MVC4通过id更新表单

    用户需求是:一个表单一旦创建完,其中大部分的字段便不可再编辑.只能编辑其中部分字段. 而不可编辑是通过对input输入框设置disabled属性实现的,那么这时候直接向数据库中submit表单中的内容 ...

  10. ssh登录实现

    工程目录 配置文件详解 Spring的applicationContext.xml文件 <span ><?xml version="1.0" encoding=& ...