cxf与spring的整合:

一:服务端相关配置(配置好后启动tomocat就自动发布了接口,浏览器打开验证下)

1:导入cxf以及spring的相关jar包;

2:在web.xml中增加配置:

代码:

  <!--添加cxf配置文件-->

     <context-param>

         <param-name>contextConfigLocation</param-name>

         <param-value>classpath:cxf.xml</param-value>

     </context-param>

     <!--添加监听器-->

     <listener>

         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

     </listener>

     <!--cxf配置-->
<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>/ws/*</url-pattern>
</servlet-mapping>

3:cxf文件的配置:

注意:发布的接口和接口的具体实现都要贴上@WebService标签;

spring-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"
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://localhost:8080/ws/product -->
<jaxws:server id="inlineImplementor" serviceClass="com.floor.shop.ws.IProductService"
address="/product">
<jaxws:serviceBean>
<bean class="com.floor.shop.ws.impl.ProductService"/>
</jaxws:serviceBean>
</jaxws:server> </beans>

二:客户端的相关配置:

0.拷贝jar包
1.在cmd中运行wsdl2java "http://localhost:8080/ws/product?wsdl 生成客户端代码
2.在spring配置文件中配置客户信息

在客户端项目的src文件夹下运行dos命令:

wsdl2java  +服务端提供的访问接口

2:客户端的   spring-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"
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://localhost:8080/ws/product -->
<jaxws:client id="productService" serviceClass="com.floor.shop.ws.IProductService" address="http://localhost:8081/ws/product"/> </beans>

3:客户端中方法的调用:

代码:

  ClassPathXmlApplicationContext cxt =
new ClassPathXmlApplicationContext("spring/cxf_Client.xml"); IProductService productService = (IProductService)cxt.getBean("productService");
User user = new User();
user.setUserName("张无忌");
String s = productService.buyProduct(user);
System.out.println("s="+s);

cxf与spring的整合的更多相关文章

  1. WebService--CXF以及CXF与Spring的整合(jaxws:server形式配置)

    前言:好记性不如烂笔头,写博客的好处是,以前接触的东西即便忘记了,也可以从这里查找. Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来 ...

  2. CXF和spring整合遇到的问题:No bean named 'cxf' is defined

    今天在做ws和spring整合的时候,很不幸的遇到了这个问题,百度了好久,竟然没人遇到这个问题,后来谷歌了一下,都是遇到这个问题的了...在看到一篇文章中提到了cxf.xml,所以我果断的打开这个配置 ...

  3. 【WebService】WebService之CXF和Spring整合(六)

    前面介绍了WebService与CXF的使用,项目中我们经常用到Spring,这里介绍CXF与Spring整合 步骤 1.创建一个Maven Web项目,可以参照:[Maven]Eclipse 使用M ...

  4. Spring boot 整合CXF webservice 遇到的问题及解决

    将WebService的WSDL生成的代码的命令: wsimport -p com -s . com http://localhost:8080/service/user?wsdl Spring bo ...

  5. spring mvc整合mybaitis和log4j

    在上一篇博客中,我介绍了在mac os上用idea搭建spring mvc的maven工程,但是一个完整的项目肯定需要数据库和日志管理,下面我就介绍下spring mvc整合mybatis和log4j ...

  6. WebService--CXF与Spring的整合(jaxws:endpoint形式配置)以及客户端调用(spring配置文件形式,不需要生成客户端代码)

    一.CXF与Spring整合(jaxws:endpoint形式配置) 工具要点:idea.maven 1.新建一个maven项目 <?xml version="1.0" en ...

  7. struts2 spring mybatis 整合(test)

    这几天搭了个spring+struts2+mybatis的架子,练练手,顺便熟悉熟悉struts2. 环境:myEclipse10+tomcat7+jdk1.6(1.8的jre报错,所以换成了1.6) ...

  8. 【Java EE 学习 79 下】【动态SQL】【mybatis和spring的整合】

    一.动态SQL 什么是动态SQL,就是在不同的条件下,sql语句不相同的意思,曾经在“酒店会员管理系统”中写过大量的多条件查询,那是在SSH的环境中,所以只能在代码中进行判断,以下是其中一个多条件查询 ...

  9. 3.springMVC+spring+Mybatis整合Demo(单表的增删该查,这里主要是贴代码,不多解释了)

    前面给大家讲了整合的思路和整合的过程,在这里就不在提了,直接把springMVC+spring+Mybatis整合的实例代码(单表的增删改查)贴给大家: 首先是目录结构: 仔细看看这个目录结构:我不详 ...

随机推荐

  1. MT【270】含参绝对值函数最大之二

    已知$f(x)=2ax\cos^2x+(a-1)\cos x-1,a>0$,记$|f(x)|$的最大值为$A$,1)求A.2)证明:$|-2a\sin 2x+(1-a)\sin x|\le 2A ...

  2. python学习日记(文件操作练习题)

    登录注册(三次机会) name = input('请注册姓名:') password = input('请注册密码:') with open('log',mode='w',encoding='utf- ...

  3. BZOJ 2728: [HNOI2012]与非(位运算)

    题意 定义 NAND(与非)运算,其运算结果为真当且仅当两个输入的布尔值不全为真,也就是 A NAND B = NOT(A AND B) ,运算位数不会超过 \(k\) 位, 给你 \(n\) 个整数 ...

  4. Codeforces | CF1029F 【Multicolored Markers】

    这道题其实难度应该小于紫题...除了一点小特判以外没什么难度...\(\leq50\)行代码即可\(AC\)此题 题目大意:给定两个数\(a,b(1\leq a,b\leq 10^{14})\)分别表 ...

  5. LVS负载均衡群集(NAT)

    ----构建NAT模式的LVS群集----------client---------------LVS----------------WEB1-----------WEB2------------NF ...

  6. scrapy 基本命令

    创建scrapy项目 scrapy startproject project_name 创建爬虫文件 scrapy genspider [-t template] <name> <d ...

  7. hdu 2159 FATE (二维完全背包)

    Problem Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务.久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级.现 ...

  8. JavaScript原型详解

    1,前言 下面是2008年Github创建以来,各种编程语言的排名情况 排名其中JavaScript自2015年之后就盘踞第一名,成为github上被使用最多的语言,早期,JS的使用还主要集中于浏览器 ...

  9. java List<String> 转换成带逗号的字符串

    使用commons-lang3-3.3.2.jar org.apache.commons.lang3.StringUtils.join(applyNameList, ",");

  10. 【译】11. Java反射——动态代理

    原文地址:http://tutorials.jenkov.com/java-reflection/dynamic-proxies.html 博主最近比较忙,争取每周翻译四篇.等不急的请移步原文网页. ...