cxf2.7.10 与 spring3.0.5集成
开发环境:
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集成的更多相关文章
- cxf2.7.10与Spring3.0.5集成时报错如下
严重: Error listenerStart 2014-3-29 22:25:20 org.apache.catalina.core.StandardContext start 严重: Contex ...
- 开发基础框架: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 二 ...
- spring3.0的jar包详解
1. spring.jar 是包含有完整发布模块的单个jar 包. 2. org.springframework.aop 包含在应用中使用Spring的AOP特性时所需的类. 3. org.sprin ...
- Cxf + Spring3.0 入门开发WebService
转自原文地址:http://sunny.blog.51cto.com/182601/625540/ 由于公司业务需求, 需要使用WebService技术对外提供服务,以前没有做过类似的项目,在网上搜寻 ...
- Spring3.0.5jar包用法详解 [转载]
Spring3.X以后jar包进行了重构,取消了原来2.X版本中的总的spring.jar包,而是把总包中的功能全部分开打包.正在向osgi靠拢. 各个jar包详解如下: 1. org.springf ...
- Spring3.0 与 MyBatis框架 整合小实例
本文将在Eclipse开发环境下,采用Spring MVC + Spring + MyBatis + Maven + Log4J 框架搭建一个Java web 项目. 1. 环境准备: 1.1 创建数 ...
- spring3.0+Atomikos 构建jta的分布式事务 -- NO
摘自: http://gongjiayun.iteye.com/blog/1570111 spring3.0+Atomikos 构建jta的分布式事务 spring3.0已经不再支持jtom了,不过我 ...
- 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 ...
- spring3.0+Atomikos 构建jta的分布式事务
摘自: http://gongjiayun.iteye.com/blog/1570111 spring3.0+Atomikos 构建jta的分布式事务 spring3.0已经不再支持jtom了,不过我 ...
随机推荐
- poj2960 S-Nim
大意:有n堆石子,每堆石子个数已知,两人轮流从中取石子, 每次可取的石子数x满足x属于集合S(k) = {s1,s2,s3...sk-1},问先拿者是否有必胜策略? 裸nim,可以用记忆化搜索. #i ...
- Visual studio 使用正则表达查找替换
原文 http://www.cnblogs.com/shineqiujuan/archive/2012/07/04/2575535.html 正则表达式是查找和替换文本模式的一种简洁而灵活的表示法. ...
- 解决SQL server不支持utf8,php却用utf8的矛盾问题
function convert2utf8($string) { return iconv("gbk","utf-8",$string); } function ...
- Poj3468-A Simple Problem with Integers(伸展树练练手)
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...
- 【HDU 4738 Caocao's Bridges】BCC 找桥
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题意:给定一个n个节点m条边的无向图(可能不连通.有重边),每条边有一个权值.判断其连通性,若双 ...
- Android 开发笔记-Eclipse中文乱码
使用eclipse时经常中文乱码网上搜罗了下解决办法: 使用Eclipse编辑文件经常出现中文乱码或者文件中有中文不能保存的问题,Eclipse提供了灵活的设置文件编码格式的选项,我们可以通过设置 ...
- Android使用bindService启动服务
1.Service package com.example.ebobo; import java.util.Timer; import java.util.TimerTask; import andr ...
- qt model/view 架构基础介绍之QTreeWidget
# -*- coding: utf-8 -*- # python:2.x #说明:QTreeWidget用于展示树型结构,也就是层次结构同前面说的 QListWidget 类似,这个类需要同另外一个辅 ...
- Bootstrap在线编辑器简单分享
Bootstrap 已经使响应式网站开发变得简单很多. 但是如果你不必手动写全部代码,事情会如何呢? 如果你可以自由地选择你想要使用的Bootstrap 组件.并可以把它们拖拽到画布中,事情会如何呢? ...
- 在多线程环境中使用Jedis
Jedis是一个Java语言的Redis客户端,它为Java语言连接与操作Redis提供了简单易用的接口. Jedis不是线程安全的.故不应该在多线程环境中共用一个Jedis实例.可是.也应该避免直接 ...