本文主要介绍在Eclipse[3.3.2]安装CXF插件。开发一个简单的java web service,以及和Spring的集成。
安装插件:
1,下载STP all_in_one,从http://ftp.daum.net/eclipse/stp/old-downloads-page/可以下载stp-all-in-one-incubation-0.7.0.200711162004.zip
安装这个插件,可以用link文件的方式安装,可参考 http://blog.csdn.net/kkdelta/archive/2009/03/12/3983999.aspx
2,下载CXF 运行环境所需的Jar包,
http://people.apache.org/repo/m2-snapshot-repository/org/apache/cxf/apache-cxf/
我用的是 apache-cxf-2.1-incubator-20080414.232258-49.zip
3,打开eclipse后,在菜单栏,windows-->preference-->soa tools 如下图,说明插件安装成功。
4,配置CXF运行环境,如下图,installed Runtimes---- Add--Appach CXF 2.0--Next 指定解压缩后的apache-cxf-2.1-incubator-20080414.232258-49.zip的路径。
开发Web Java Service1,新建一个web project,在 这个project里建立下面的interface:package com.test.cxf;public interface WSprovider {public String testWS(String msgIn);}然后在这个建好后的project上点右键,JAX-WS Tools ---Enable JAX-WS --java first programing mode, 选择运行cxf环境-- 选择新建的interface--finish。你的interface将被加上Java anotation如下:
packagecom.test.cxf;
importjavax.jws.WebService;
@WebService(name="WSprovider", targetNamespace="http://cxf.test.com/")
publicinterfaceWSprovider {
publicString testWS(String msgIn);
}
2,在outline视图,选中testws(),右键选JAX-WX tools--〉create web method你的interface将被加上Java anotation如下:
@WebService(name="WSprovider", targetNamespace="http://cxf.test.com/")
publicinterfaceWSprovider {
@WebMethod(operationName="testWS", exclude=false)
@ResponseWrapper(className="com.test.cxf.TestWSResponse", localName="testWSResponse", targetNamespace="http://cxf.test.com/")
@RequestWrapper(className="com.test.cxf.TestWS", localName="testWS", targetNamespace="http://cxf.test.com/")
publicString testWS(String msgIn);
}
3,然后在project上点右键,JAX-WS Tools ---Generate All会生成interface的实现类如下:
@WebService(endpointInterface ="com.test.cxf.WSprovider", serviceName ="WSproviderService")
publicclassWSproviderImplimplementsWSprovider {
publicjava.lang.String testWS(java.lang.String arg0) {
........
}
}
到此,简单的web service的开发就算完成了。
集成Spring
1,在WEB-INF下建立一个bean.xml文件:
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">
id="testEndpoint"
implementor="#testService"
wsdlLocation="classpath:wsdl/prjCXFWeb.wsdl"
address="/WSCXFProviderPort">
2,对生成的wsdl文件修改:把
改成 在你的src下新建一个wsdl文件,把改后的wsdl copy到此【为了对应bean.xml中的wsdlLocation】。3,在web.xml中加入:
contextConfigLocation
WEB-INF/beans.xml
org.springframework.web.context.ContextLoaderListener
CXFServlet
org.apache.cxf.transport.servlet.CXFServlet
1