WS之cxf与spring整合1

1、在web.xml中加入CXFServlet:
<!-- 下面表示所有来自/cxfservice/*的请求,都交给 CXFServlet来处理 。-->
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
2、在spring的配置文件中导入cxf的配置:
<?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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<context:annotation-config /> <!-- 对属性文件 -->
<context:component-scan base-package="cn" />
<bean id="userService" class="cn.tdtk.ws.dao.impl.UserServiceImpl"/>
<bean id="helloWorldImpl" class="cn.tdtk.ws.dao.impl.HelloWorldImpl">
<property name="us" ref="userService"/>
</bean>
<!-- web应用的类加载路径有两类:
1. WEB-INF/classes 目录。
2. 加载WEB-INF/lib 目录下的cxf的jar文件中的META-INF下的文件。-->
<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"/>
<!-- implementor指定webservice的服务提供者,有两种表示形式:
1. 通过已知服务器的类名(implementor="cn.tdtk.ws.dao.impl.HelloWorldImpl")。
2. 设置为容器中的一个Bean (implementor="#helloWorldImpl").
-->
<jaxws:endpoint
implementor="#helloWorldImpl"
address="/helloService">
<!-- 添加in拦截器 -->
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<!-- <bean class="cn.tdtk.ws.interceptor.AuthInterceptor"/> -->
</jaxws:inInterceptors>
</jaxws:endpoint>
</beans>
3、调用spring的webservice:
将webservice生成java文件:

测试代码:
public class ClientMain {
/**
* @param args
*/
public static void main(String[] args) {
HelloWorldImplService factory= new HelloWorldImplService();
HelloWorld hw = factory.getHelloWorldImplPort();
String s = hw.sayHello("tom");
System.out.println(s);
}
4、通过依赖注入将业务层注入到webservice中:
public class HelloWorldImpl implements HelloWorld {
private UserService us;
@Override
public String sayHello(String name) {
return name + ",你好,现在的时间是: "+new Date();
}
@Override
public List<Cat> getCatsByUser(User user) {
// 在这里只是调用业务逻辑组件,而不实现,具体的实现由业务类去完成
return us.getCatsByUser(user);
}
@Override
public Map<String, Cat> getAllCats() {
return us.getAllCats();
}
public void setUs(UserService us) {
this.us = us;
}
}
WS之cxf与spring整合1的更多相关文章
- WS之cxf与spring整合2
在action中加入webservice
- 【WebService】WebService之CXF和Spring整合(六)
前面介绍了WebService与CXF的使用,项目中我们经常用到Spring,这里介绍CXF与Spring整合 步骤 1.创建一个Maven Web项目,可以参照:[Maven]Eclipse 使用M ...
- CXF和spring整合遇到的问题:No bean named 'cxf' is defined
今天在做ws和spring整合的时候,很不幸的遇到了这个问题,百度了好久,竟然没人遇到这个问题,后来谷歌了一下,都是遇到这个问题的了...在看到一篇文章中提到了cxf.xml,所以我果断的打开这个配置 ...
- webservice的cxf和spring整合发布
1.新建一个web项目 2.导入cxf相应的jar包,并部署到项目中 3.服务接口 package com.xiaostudy; /** * @desc 服务器接口 * @author xiaostu ...
- webservice的cxf和spring整合客户端开发
1.新建一个java项目 2.导入cxf相关的jar包,并部署到项目中 3.用命令生成客户端使用说明文档 wsdl2java -p com.xiaostudy -d . http://127.0.0. ...
- CXF、Spring整合的SOAP Web Service服务端
1.建工程,导入CXFjar包 2.服务接口 package com.cxf.soap; import java.util.List; import javax.jws.WebService; @We ...
- CXF 与Spring整合配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java ...
- 13_CXF和Spring整合发布服务
[服务端] 第一步:建立一个Web项目 第二步:填充CXF jar包 第三步:创建接口及服务类 [工程截图(对比之前的WebService_CXF_Server00)] [applicationCon ...
- Spring整合CXF,发布RSETful 风格WebService(转)
Spring整合CXF,发布RSETful 风格WebService 这篇文章是承接之前CXF整合Spring的这个项目示例的延伸,所以有很大一部分都是一样的.关于发布CXF WebServer和Sp ...
随机推荐
- RTC硬件时钟设置修改【转】
转自:http://os.chinaunix.net/a2008/0526/981/000000981211.shtml 这两天一直在做i2c设备驱动的理解,所以很少更新文章. 由于对于表计来说,RT ...
- C# 字符流打印类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- [转]SQL语句优化技术分析
一.操作符优化 1.IN 操作符 用IN写出来的SQL的优点是比较容易写及清晰易懂,这比较适合现代软件开发的风格.但是用IN的SQL性能总是比较低的,从Oracle执行的步骤来分析用IN的SQL与不用 ...
- hihoCoder 1040 矩形判断(计算几何)
http://hihocoder.com/problemset/problem/1040 首先判断四条线段是否相交,给出八个点,如果有一些点重合,并且不同坐标的点只有4个的话,表示可以构成四边形. 然 ...
- 《OD大数据实战》Kafka入门实例
官网: 参考文档: Kafka入门经典教程 Kafka工作原理详解 一.安装zookeeper 1. 下载zookeeper-3.4.5-cdh5.3.6.tar.gz 下载地址为: http://a ...
- HDU 1422 重温世界杯
题目中说只需按照所给顺序,不论起点,输出能连续旅游的最多的城市 就是不论起点这句,我就卡住了.. 看了别人的题解,循环个2n-1次便是把所有的起点都考虑进去了. 更详细的解释在代码的注释里. //#d ...
- Web Forms vs Web MVC
MVC相对于WebForm来说更难学习,但性能优于WebForm,比较适合大型项目,开发成本较高,但耦合度低,易于维护,没有太多的现成控件,开发效率较低.对WebForm有基础的人反而不太容易学MVC ...
- 【同行说技术】swift最全学习资料汇集(一)
Swift,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序.2015年12月4日,苹果公司宣 ...
- 每天一个Linux命令(3): cd
Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. 所以,学习Linux 常用命令,首先就要学好 cd 命令的使用方法技巧. 1. ...
- 【英语】Bingo口语笔记(2) - 吞音