从网络上找了很多入门的例子,但大部分都是有这样或那样的问题,搞的头大。
?? 这里根据自己搭建的过程,整理出一个实际例子。
?? 环境:jdk1.5+,eclipse3.4,Tomcat5.5,cxf-2.1.4
???以下没有用到任何插件来生成
?? 服务端
?????一、server 端:?
??????????接口:WebServiceSample
?????????
?? 实现类:WebServiceSampleImpl
??
? 实体类:UserDTO,ReqBean,RespBean
?
?二、Spring 配置
??????
<beans?xmlns="http://www.springframework.org/schema/beans"??
????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??
????xmlns:jaxws="http://cxf.apache.org/jaxws"??
????xsi:schemaLocation="???
http://www.springframework.org/schema/beans?http://www.springframework.org/schema/beans/spring-beans.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-extension-soap.xml"?/>???

????
<import?resource="classpath:META-INF/cxf/cxf-servlet.xml"?/>???

??

????
<bean?id="jaxWsServiceFactoryBean"??
????????class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">???

????????
<property?name="wrapped"?value="true"?/>???

????????
<property?name="dataBinding"?ref="aegisBean"?/>???

????
</bean>???

??

????
<bean?id="aegisBean"??
????????class="org.apache.cxf.aegis.databinding.AegisDatabinding"?/>???

??

????
<jaxws:endpoint?id="CollectiveServices"??
????????implementor="hs.cxf.server.WebServiceSampleImpl"?address="/HelloWorld">???

????????
<jaxws:serviceFactory>???

????????????
<ref?bean="jaxWsServiceFactoryBean"/>???

????????
</jaxws:serviceFactory>???

????
</jaxws:endpoint>???
</beans>??
三.web.xml配置
<?xml?version="1.0"?encoding="UTF-8"?>
<!DOCTYPE?web-app?PUBLIC?"-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.3//EN"?"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app?id="WebApp_ID">
????
<display-name>cxfTest
</display-name>
????
<context-param>
????????
<param-name>contextConfigLocation
</param-name>
????????
<param-value>WEB-INF/beans.xml
</param-value>
????
</context-param>
????
<listener>
????????
<listener-class>
????????????org.springframework.web.context.ContextLoaderListener???

????????
</listener-class>
????
</listener>
????
<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>
</web-app>
这里要注意,cxf 教程上提到需要的包并不完整,还需要导入:jdom,stax-api-1.0-2.jar,jaxws-api.jar?这些包
?我使用的包如下:
?

aopalliance-1.0.jar

asm-2.2.3.jar

commons-logging-1.1.1.jar

cxf-2.1.4.jar

geronimo-activation_1.1_spec-1.0.2.jar

geronimo-annotation_1.0_spec-1.1.1.jar

geronimo-javamail_1.4_spec-1.3.jar

geronimo-servlet_2.5_spec-1.2.jar

geronimo-ws-metadata_2.0_spec-1.1.2.jar

jaxb-api-2.1.jar

jaxb-impl-2.1.9.jar

jaxen-core.jar

jaxen-jdom.jar

jaxws-api.jar

jdom.jar

jetty-6.1.9.jar

jetty-util-6.1.9.jar

neethi-2.0.4.jar

saaj-api-1.3.jar

saaj-impl-1.3.2.jar

saxpath.jar

spring-beans-2.0.8.jar

spring-context-2.0.8.jar

spring-core-2.0.8.jar

spring-web-2.0.8.jar

stax-api-1.0-2.jar

wsdl4j-1.6.2.jar

wstx-asl-3.2.6.jar

xalan.jar

xml-resolver-1.2.jar

XmlSchema-1.4.3.jar
然后启动tomcat,输入http://IP:端口/模块名/ws 查看你生成的服务端,可使用xmlspy来进行测试。