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的更多相关文章

  1. WS之cxf与spring整合2

    在action中加入webservice

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

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

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

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

  4. webservice的cxf和spring整合发布

    1.新建一个web项目 2.导入cxf相应的jar包,并部署到项目中 3.服务接口 package com.xiaostudy; /** * @desc 服务器接口 * @author xiaostu ...

  5. webservice的cxf和spring整合客户端开发

    1.新建一个java项目 2.导入cxf相关的jar包,并部署到项目中 3.用命令生成客户端使用说明文档 wsdl2java -p com.xiaostudy -d . http://127.0.0. ...

  6. CXF、Spring整合的SOAP Web Service服务端

    1.建工程,导入CXFjar包 2.服务接口 package com.cxf.soap; import java.util.List; import javax.jws.WebService; @We ...

  7. CXF 与Spring整合配置

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java ...

  8. 13_CXF和Spring整合发布服务

    [服务端] 第一步:建立一个Web项目 第二步:填充CXF jar包 第三步:创建接口及服务类 [工程截图(对比之前的WebService_CXF_Server00)] [applicationCon ...

  9. Spring整合CXF,发布RSETful 风格WebService(转)

    Spring整合CXF,发布RSETful 风格WebService 这篇文章是承接之前CXF整合Spring的这个项目示例的延伸,所以有很大一部分都是一样的.关于发布CXF WebServer和Sp ...

随机推荐

  1. js获取项目根路径

    //js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...

  2. 利用SOLR搭建企业搜索平台 之——MultiCore

    Solr Multicore 是 solr 1.3 的新特性.其目是一个solr实例,可以有多个搜索应用. 下面着手来将solr给出的一个example跑出来.这篇文章是基于<利用SOLR搭建企 ...

  3. Perl文件读写

    Perl File Handling: open, read, write and close files #==================== Opening files Solution 1 ...

  4. C# 对List成员排序的简单方法

    网上看到的方法,实在太方便了,转过来保存,原链接: http://blog.csdn.net/wanzhuan2010/article/details/6205884 using System; us ...

  5. 【分享】哪个OS X版本支持哪个Xcode的版本?

    在安装Xcode时,会碰到跟OS X操作系统匹配的问题,对照下下面几个表,以免给自己带来编译不过或者奇怪的错误等问题 以下列表来自网络: Xcode 1.0 - Xcode 2.x (before i ...

  6. [转载]hao123军事频道首页JQ焦点图

    适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗. *本作品由[站长素材]收集整理,转载请注明出处! 下载地址

  7. VS2010 需要缺少的web组件才能加载该项目

    到的问题是解决方案中部分项目无法加载, 提示需要缺少的web组件才能加载该项目,是否通过WEB安装组件来网络安装, 点击确定以后就什么也没有了. 到微软网站去下载Microsoft Web Platf ...

  8. Npoi Web 项目中(XSSFWorkbook) 导出出现无法访问已关闭的流的解决方法

    原本在CS项目中用的好好的在BS项目中既然提示我导出出现无法访问已关闭的流的解决方法 比较郁闷经过研究 终于解决了先将方法发出来 让遇到此问题的筒子们以作参考 //新建类 重写Npoi流方法 publ ...

  9. php里少用到的session_module_name,以及session的key值限制,简单将session存储为json格式数据的方法

    这个函数的作用就是动态的设置php.ini里的session_save_handler,配合session_set_savepath可以在程序里自由配置session的后台方式. session_ca ...

  10. UVa11582 Colossal Fibonacci Numbers!

    #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> us ...