Apache CXF测试记录

一:给出管方网址吧

http://cxf.apache.org/

 

二:基于自己的测试 ,在jdk1.6,tomcat6.0环境下,只有cxf-2.1.x以下(不含2.1.x版本)的版本可以在不附加配置jdk或tomcat下,测试成功,我选择了cxf-2.0.8,点这里下载这个版本

 

三:下载后,筛选出必备的几个jar包 (服务器端的),问我是怎么筛选的,自个儿一个一个的试吧,经出必须的jar包名:

commons-logging-1.1.1.jar

cxf-2.0.8.jar

jaxb-api-2.0.jar

jaxb-impl-2.0.5.jar

wsdl4j-1.6.2.jar

xml-resolver-1.2.jar

XmlSchema-1.4.2.jar

spring.jar

说明一下:spring.jar里包含了:spring-core.jar,spring-web.jar,spring-beans.jar,spring-context.jar,或着你直接用spring官网下载的spring.jar也应该可以

 

四:web.xml配置如下

<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/springConfig/applicationContext.xml</param-value> </context-param> <!-- 配置Spring监听器 --> <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>5</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/ws/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>

 

五:applicationContext.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://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" /> <jaxws:endpoint id="hello" implementor="test.hello.HelloImpl" address="/hello"/> </beans>

 

六:新建一个接口

package test.hello; import javax.jws.WebParam; import javax.jws.WebService; @WebService(name="helloService") public interface IHello { public String sayHello(@WebParam(name="name") String name); }

 

七:实现该接口

package test.hello; import javax.jws.WebParam; import javax.jws.WebService; @WebService(endpointInterface="test.hello.IHello",serviceName="helloService") public class HelloImpl implements IHello { public String sayHello(@WebParam(name="name") String name) { return "Hello From CXF KO: " + name; } }

 

八:客户端测试代码,一定要在不同的工程下测试,为了简单,我用了cxf官方下载的所有jar包做为测试用了,呵呵

package test; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import test.hello.IHello; public class CxfClient { public static void main(String[] args) { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(IHello.class); factory.setAddress("http://localhost/ws/hello"); IHello client = (IHello)factory.create(); System.out.println(client.sayHello("collon")); } }

 

九:参考网页

http://www.cnblogs.com/TV9/archive/2008/06/30/1232726.html

http://blog.csdn.net/yyh30/archive/2008/09/20/2952145.aspx

 

十:Fighting And Keep Moving!!

你可能感兴趣的:(apache,spring,String,webservice,测试,encoding)