在javaeye里参考大牛们的帖子去配置spring2.5+hibernate3.2+CXF2.1,最终解决了路径问题后,终于成功了!
CXF是Apache的一个重点项目,终于放出来了,因为它跟spring的结合很方便,于是就用一下,还是要自己动手一步步弄一下,才知道其配置上的一些小细节(如果用插件的话,就感觉不到它跟spring的关系和不知道它的很多细节,所以推荐不要用插件的好)。
在这里顺带提一下,spring2.5结合junit4.4可以很容易地运用annotation来进行testcase的编写,不过要注意的是eclipse3.3或者eclipose3.4,里头自带的junit4是junit4.3版本的,缺少需要的方法,所以要去下载最新的junit4.4版,然后替换掉eclipse插件里的junit.jar包。
  1. 准备依赖包,依赖包不用想那么多,我在这里是把握的项目包弄个截图,所以是很多的,重点是spring,hibernate,CXF*这些包。
    CXF使用备忘
  2. 在web.xml文件中添加以下servlet配置:
    CXF使用备忘<!-- CXF 配置 -->
    CXF使用备忘    
    <servlet>
    CXF使用备忘        
    <servlet-name>CXFServlet</servlet-name>
    CXF使用备忘        
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    CXF使用备忘        
    <load-on-startup>1</load-on-startup>
    CXF使用备忘    
    </servlet>
    CXF使用备忘    
    <servlet-mapping>
    CXF使用备忘        
    <servlet-name>CXFServlet</servlet-name>
    CXF使用备忘        
    <url-pattern>/services/*</url-pattern>
    CXF使用备忘    
    </servlet-mapping>

  3. 添加applicationContext-cxf.xml文件到上下文,配置如下:
    CXF使用备忘<?xml version="1.0" encoding="UTF-8"?>
    CXF使用备忘
    <beans xmlns="http://www.springframework.org/schema/beans"
    CXF使用备忘    xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
    CXF使用备忘    xmlns:jaxws
    ="http://cxf.apache.org/jaxws"
    CXF使用备忘    xsi:schemaLocation
    ="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
    CXF使用备忘    default-autowire
    ="byName" default-lazy-init="true">
    CXF使用备忘    
    <description>基于Apache CXF的Web Service配置文件</description>
    CXF使用备忘    
    CXF使用备忘    
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    CXF使用备忘    
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    CXF使用备忘    
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
    CXF使用备忘    
    <import
    CXF使用备忘        
    resource="classpath:META-INF/cxf/cxf-extension-javascript-client.xml"/>
    CXF使用备忘    
    CXF使用备忘    
    <bean id="helloWorldImpl" class="com.lbg.ws.test.impl.HelloWorld"/>
    CXF使用备忘    
    CXF使用备忘    
    <jaxws:endpoint id="helloWorld" implementor="#helloWorldImpl"
    CXF使用备忘        address
    ="/HelloWorld"/>
    CXF使用备忘
    </beans>

  4. 建立webservice的接口与实现:
    CXF使用备忘package com.lbg.ws.test;
    CXF使用备忘
    CXF使用备忘
    import javax.jws.WebMethod;
    CXF使用备忘
    import javax.jws.WebService;
    CXF使用备忘
    CXF使用备忘@WebService(name
    ="HelloWorld")
    CXF使用备忘package com.lbg.ws.test.impl;
    CXF使用备忘
    CXF使用备忘
    import javax.jws.WebService;
    CXF使用备忘
    CXF使用备忘
    import com.lbg.ws.test.IHelloWorld;
    CXF使用备忘
    CXF使用备忘@WebService(endpointInterface
    ="com.lbg.ws.test.IHelloWorld")
    }

相关文章:

  • 2021-05-21
  • 2021-12-15
  • 2021-10-30
  • 2021-05-19
  • 2021-08-22
  • 2021-08-29
  • 2021-07-27
  • 2021-11-09
猜你喜欢
  • 2021-09-27
  • 2021-06-13
  • 2021-07-27
  • 2022-02-04
  • 2021-07-22
  • 2021-08-13
  • 2021-10-25
相关资源
相似解决方案