开发环境:Eclipse indigo + Tomcat6.0 + JDK1.6 + CXF2.5
1、Eclipse新建一个Dynamic Web Project工程,创建时即可以选择运行环境,如Tomcat6.0、CXF2.5。
建好后在工程属性Properties->Java Build Path->Source->Default output folder里把:项目名/build/classes修改为:项目名/WebContent/WEB-INF/classes(只是习惯,也可不改)
2、创建后会包含所有CXF库,如果创建时没有配置、选择CXF,可以从cxf文件夹下的lib文件夹中复制cxf.jar、spring-core.jar、spring-web.jar、spring-beans.jar、spring-context.jar、commons-logging.jar、fastinfoset.jar、needhi.jar、wsdl4j.jar、XmlSchema.jar,在Eclipse->CxfTest->Webroot->WEB-INF->lib点击右键选择粘贴(当然,也可以直接复制到该目录下然后刷新lib)
1、Eclipse新建一个Dynamic Web Project工程,创建时即可以选择运行环境,如Tomcat6.0、CXF2.5。
建好后在工程属性Properties->Java Build Path->Source->Default output folder里把:项目名/build/classes修改为:项目名/WebContent/WEB-INF/classes(只是习惯,也可不改)
2、创建后会包含所有CXF库,如果创建时没有配置、选择CXF,可以从cxf文件夹下的lib文件夹中复制cxf.jar、spring-core.jar、spring-web.jar、spring-beans.jar、spring-context.jar、commons-logging.jar、fastinfoset.jar、needhi.jar、wsdl4j.jar、XmlSchema.jar,在Eclipse->CxfTest->Webroot->WEB-INF->lib点击右键选择粘贴(当然,也可以直接复制到该目录下然后刷新lib)
3、编辑web.xml
- 在web.xml文件中添加以下servlet配置:
-
aram><context-p
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/service-beans.xml</param-value> //指定配置文件
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
< servlet >
servlet-name CXFServlet </ servlet-class org.apache.cxf.transport.servlet.CXFServlet load-on-startup 1 servlet-mapping url-pattern /services/* >
- 添加service-beans.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:jaxws ="http://cxf.apache.org/jaxws"
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"
default-autowire ="byName" default-lazy-init ="true" description 基于Apache CXF的Web Service配置文件
import resource ="classpath:meta-inf/cxf/cxf.xml" /> ="classpath:meta-inf/cxf/cxf-servlet.xml" ="classpath:meta-inf/cxf/cxf-extension-soap.xml" import
="classpath:meta-inf/cxf/cxf-extension-javascript-client.xml" bean id ="helloWorldImpl" class ="com.lbg.ws.test.impl.HelloWorld" jaxws:endpoint ="helloWorld" implementor ="#helloWorldImpl"
address ="/HelloWorld" beans