CXF 在spring中配置
来源:互联网 发布:嵌入式系统的软件 编辑:程序博客网 时间:2024/05/21 09:59
在使用CXF写WebService的项目里 经常会和spring框架一起使用,下面将列出CXF如何在Spring框架中配置:
一、服务端配置:
1、首先项目导入CXF的jar包:org.apache.cxf:apache-cxf:3.1.3
2、在你spring配置文件的地方创建spring-cxf-servlet.xml文件 文件内容为:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:client id="webServiceClient" serviceClass="com.ct10000.sc.interfaces.internal.cvp.service.webService.IWebService" address="http://localhost:8080/cvp/WsWebService" /></beans>
3、在spring-core.xml文件里(spring核心配置文件)里 <importresource="spring-cxf-servlet.xml"/> 引入创建的xml文件
4、在WEB-INF目录下的web.xml配置文件里 写入
<!-- CXF servlet-->
<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>/*</url-pattern>
</servlet-mapping>
注意你的web.xml配置文件是否有上下文监听,如果没有写上以下代码:
<!-- 上下文监听器 --><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring-core.xml</param-value></context-param>
二、客户端配置:
1、在客户端模块的spring配置的地方创建spring-cxf-client.xml文件,内容为:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:client id="webServiceClient" serviceClass="com.ct10000.sc.interfaces.internal.cvp.service.webService.IWebService" address="http://localhost:8080/cvp/WsWebService" /></beans>注意adress要和服务端的地址对应起来
2、客户端的代码:
package com.ct10000.sc.interfaces.internal.spp.webClient;import com.ct10000.sc.entities.bean.commons.crm.qryProdInfo.ProdInfoBean;import com.ct10000.sc.interfaces.internal.cvp.service.webService.IWebService;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import java.util.List;/** * webService 客户端 * * Created by ryh on 2015/10/14. */public class WebCilent { public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("spring-cxf-client.xml");//指向客户端配置文件 IWebService service = context .getBean("webServiceClient", IWebService.class); String number = ""; String numberKey = "phoneNumber"; List<ProdInfoBean> List = service.findProdInfoByNumber(number,numberKey); }}
这样客户端的配置也就完成了 ,希望对大家有所帮助。
- CXF 在spring中配置
- Apache cxf JaxWs基本应用 (如何在Spring中配置CXF,测试的时候与一般services不一样)
- 在spring中集成webservice 框架 CXF
- CXF 在Spring中开发服务端步骤
- 基于Maven在Spring中集成CXF Web Service框架
- 基于Maven在Spring中集成CXF框架
- 在Spring中调用基于CXF框架的webService
- 在 Spring 配置文件中导入 CXF 提供 Schema、XML 详情
- 在java中使用spring整合cxf实现webservice
- 基于Maven在Spring中集成CXF,发布Web Service
- 基于Maven在Spring中集成CXF,发布Web Service
- 在 Spring 配置文件中导入 CXF 提供 Schema、XML 详情
- 在 Spring 配置文件中导入 CXF 提供 Schema、XML 详情
- cxf spring 开发与配置
- CXF客户端配置请求超时限制-SocketTimeoutException(Spring配置文件中配置和通过代码进行配置)
- Spring+cxf配置接口+mybatis配置
- 在spring中配置hibernate
- 在Spring中配置log4j
- eclipse Ctrl +左键查看源代码Source not found
- 剥开ios 系统sandbox神秘面纱
- 郁闷的串口中断 nobody cared
- 天龙txt阅读器
- DecimalFormat 用法
- CXF 在spring中配置
- win10驱动
- 卡特兰数 hdu 1023||hdu1130||hdu1134||hdu||1131||hdu1131||hdu1133||。。。。。。
- 利用基本数据类型的包装类中的方法实现类型转换
- jQWidgets v3.9.0正式发布[附下载]
- 第一章 Web MVC简介 —— 跟开涛学SpringMVC
- Javascript中call的使用
- Ugui的介绍视频地址和笔记
- Unix学习笔记-----管道的本质是什么???