CXF-09: CXF 与 Spring 的整合 之 暴露 Web Service 接口

         CXF 与 Spring 的整合:可以在传统的 Java EE 应用的基础上添加一层 Web Service 层,我们的 Java EE 应用就可以对外暴露成 Web Service,这样就允许任何平台、任何语言编写的程序来调用这个 Java EE 应用;

          

 * 在传统Spring项目基础上增加 Web Service 的步骤(SSH 已经配置过,SSM 未配过):
        1 . 复制 CXF 的 jar 包(最核心的6个), jar 包地址 http://pan.baidu.com/s/1jHJ56BW   注:请选择性复制 (Apache官网上也可以下载)
asm-3.3.jar    commons-logging-1.1.1.jar    cxf-2.4.1.jar    neethi-3.0.0.jar    wsdl4j-1.6.2.jar    xmlschema-core-2.0.jar
        2 . 在 web.xml 配置CXF的核心控制器:CXFServlet;
        3 . 在 Spring 配置文件中导入 CXF 提供 Schema、XML(cxf.jar 包里提供)
                * Schema 文件
                        <beans xmlns:jaxws="http://cxf.apache.org/jaxws" 
                                xsi:schemaLocation="
                                        http://cxf.apache.org/jaxws //命名空间
                                        http://cxf.apache.org/schemas/jaxws.xsd">//物理路径
                * XML 的配置文件
                        <import resource="classpath:META-INF/cxf/cxf.xml"/>
                        <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
                        <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

        4 . 在 Spring 配置文件中使用 jaxws:endpoint 元素类暴露 Web Service;

        5 . 添加拦截器,在 jaxws:endpoint 元素里添加 inInterceptors、outInterceptors 子元素;

 * 代码有时比语言更有说服力,新建一个 Web Project 项目代码如下:

(1)、服务器端:

          

①Food.java

public class Food {
	private Integer id;
	private String name;
	private String describe;
	public Food() {
		super();
	}
	public Food(Integer id, String name, String describe) {
		super();
		this.id = id;
		this.name = name;
		this.describe = describe;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescribe() {
		return describe;
	}
	public void setDescribe(String describe) {
		this.describe = describe;
	}
}

②User.java

public class User {
	private Integer id;
	private String name;
	private String tel;
	private String describe;
	public Integer getId() {
		return id;
	}
	public User() {
		super();
	}
	public User(Integer id, String name, String tel, String describe) {
		super();
		this.id = id;
		this.name = name;
		this.tel = tel;
		this.describe = describe;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getDescribe() {
		return describe;
	}
	public void setDescribe(String describe) {
		this.describe = describe;
	}
	@Override
	public int hashCode() {
		final int pri
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值