开发环境:

NetBeans7.4

Tomcat 6.0.32

一 服务端:

1:新建JavaWeb工程 cxfspring-server,导入jar包如下图所示:

2:在web.xml文件中添加如下配置项:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml</param-value>
</context-param>
<!--监听spring-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!--监听CXFServlet-->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>

3:新建一个com.test.server包,里面创建接口;新建一个com.test.server.impl包,里面实现接口,结构如下:

(1):IArithmeticServer.java

@WebService
public interface IArithmeticServer {
/**
* 两个整数相加
* @param opr1
* @param opr2
* @return
*/
public int addition(int opr1,int opr2); /**
* 两个整数相减
* @param opr1
* @param opr2
* @return
*/
public int subtraction(int opr1, int opr2);
}

(2):ArithmeticServerImp.java

targetNamespace = "http://server.test.com/"一定要配置否则的话看这里:
http://www.cnblogs.com/yshyee/p/3633537.html
@WebService(
endpointInterface = "com.test.server.IArithmeticServer",
targetNamespace = "http://server.test.com/")
public class ArithmeticServerImp implements IArithmeticServer{ public int addition(int opr1, int opr2) {
return opr1+opr2;
} public int subtraction(int opr1, int opr2) {
return opr1-opr2;
} }

(3):spring-config.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:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!--一个endpoint对应于一个服务-->
<jaxws:endpoint
id="arithmeticServer"
implementor="com.test.server.impl.ArithmeticServerImp"
address="/ArithmeticServer"/> </beans>

二 客户端:

1:新建JavaWeb工程,cxf-spring-client,导入的jar包与服务端相同。

2:新建一个测试类:通过动态方式调用CXF WebService。

public class Test {
public static void main(String args[]) throws Exception{
fun1();
} public static void fun1() throws Exception{
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
Client client = clientFactory.createClient("http://localhost:8080/cxfspring-server/ws/ArithmeticServer?wsdl"); Object[] result = client.invoke("addition", 1,2);
System.out.println("1+2:"+result[0]); result = client.invoke("subtraction", 1,2);
System.out.println("1-2:"+result[0]);
}
}

3:运行结果:

信息: Created classes: com.test.server.Addition, com.test.server.AdditionResponse, com.test.server.ObjectFactory, com.test.server.Subtraction, com.test.server.SubtractionResponse
1+2:3
1-2:-1
成功构建 (总时间: 3 秒)

cxf2.7.10 与 spring3.0.5集成的更多相关文章

  1. cxf2.7.10与Spring3.0.5集成时报错如下

    严重: Error listenerStart 2014-3-29 22:25:20 org.apache.catalina.core.StandardContext start 严重: Contex ...

  2. 开发基础框架:mybatis-3.2.8 +hibernate4.0+spring3.0+struts2.3

    一:项目下载地址(点击 Source code(zip)) https://github.com/fzxblgong/frame_2014-12-15/releases 版本:v1.2大小:20M 二 ...

  3. spring3.0的jar包详解

    1. spring.jar 是包含有完整发布模块的单个jar 包. 2. org.springframework.aop 包含在应用中使用Spring的AOP特性时所需的类. 3. org.sprin ...

  4. Cxf + Spring3.0 入门开发WebService

    转自原文地址:http://sunny.blog.51cto.com/182601/625540/ 由于公司业务需求, 需要使用WebService技术对外提供服务,以前没有做过类似的项目,在网上搜寻 ...

  5. Spring3.0.5jar包用法详解 [转载]

    Spring3.X以后jar包进行了重构,取消了原来2.X版本中的总的spring.jar包,而是把总包中的功能全部分开打包.正在向osgi靠拢. 各个jar包详解如下: 1. org.springf ...

  6. Spring3.0 与 MyBatis框架 整合小实例

    本文将在Eclipse开发环境下,采用Spring MVC + Spring + MyBatis + Maven + Log4J 框架搭建一个Java web 项目. 1. 环境准备: 1.1 创建数 ...

  7. spring3.0+Atomikos 构建jta的分布式事务 -- NO

    摘自: http://gongjiayun.iteye.com/blog/1570111 spring3.0+Atomikos 构建jta的分布式事务 spring3.0已经不再支持jtom了,不过我 ...

  8. Jbpm4.4+hibernate3.5.4+spring3.0.4+struts2.1.8整合例子(附完整的请假流程例子,jbpm基础,常见问题解决)

    Jbpm4.4+hibernate3.5.4+spring3.0.4+struts2.1.8 整合例子(附完整的请假流程例子). 1.jbpm4.4 测试环境搭建 2.Jbpm4.4+hibernat ...

  9. spring3.0+Atomikos 构建jta的分布式事务

    摘自: http://gongjiayun.iteye.com/blog/1570111 spring3.0+Atomikos 构建jta的分布式事务 spring3.0已经不再支持jtom了,不过我 ...

随机推荐

  1. Android 开发中关于layoutinflater

    Inflater英文意思是膨胀,在Android中应该是扩展的意思吧. LayoutInflater的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout ...

  2. Nginx 内置变量,细化规则,真实IP获取及限制连接请求

    希望下周测试之后能用起来!!!感觉很有用的. http://www.bzfshop.net/article/176.html http://www.cr173.com/html/19761_1.htm ...

  3. 新唐的icp和isp

    ICP 的意思是 "在电路编程"(in Circuit Programming),PC 电脑可以运行 “NuMicro ICP Programming Tool”软件通过 Nu-L ...

  4. WPF 如何缓解大量控件加载缓慢的问题

    最近有一个项目需要加载大量的控件,导致系统出现卡顿问题,经过几天的努力,终于搞定了,写一下备忘. 解决方案是首次加载时只显示可见区域控件,之后使用辅助线程进行分批加载,将分批加载的线程优先级别设置为空 ...

  5. UVA1218--树形DP

    没有看书和题解做的一道树形DP题,思路很清晰..只是debug上花了很久的时间才发现看错了条件..并不是每个点都只能和一台服务器相邻,而是非服务器的点只能和一台服务器相邻..看错了一个条件差距大了去了 ...

  6. postgresql C/C++ API 接口

    1,postgresql学习uri推荐 http://www.php100.com/manual/PostgreSQL8/ http://www.php100.com/manual/PostgreSQ ...

  7. 【转】DM8168添加DSP音频编解码算法--集成现有voice或audio codec

    本文根据“How to integrate audio/voice in RPE in EZSDK.pdf”整理,建议读者直接下载,参考原文件.原文件下载链接: http://download.csd ...

  8. Unity Navigation自动寻路

    NavMesh(导航网格) 是3D游戏世界中主动寻路的一种技术,如果你想让游戏人物能自动绕开障碍物到达目的地.那你就来学习下 Navigation导航技术吧O(∩_∩)O~ 首先创建一个项目创建Pan ...

  9. 01串(dp)

    01串 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 ACM的zyc在研究01串,他知道某一01串的长度,但他想知道不含有“11”子串的这种长度的01串共有多少个, ...

  10. 动态SQL的执行,注:exec sp_executesql 其实可以实现参数查询和输出参数的

    本文转自:http://www.cnblogs.com/hnsdwhl/archive/2011/07/23/2114730.html 当需要根据外部输入的参数来决定要执行的SQL语句时,常常需要动态 ...