Official homepage: http://cxf.apache.org/
A detailed sample is provided after the download. Here we will first demonstrate a simple project.
Create a project as shown in:
Client test code: testserviceclient. Java
- Package JP. co. APM. client;
- Import JP. co. APM. Service. testservice;
- Import org. Apache. cxf. frontend. clientproxyfactorybean;
- Public class testserviceclient {
- Public static void main (string [] ARGs ){
- Clientproxyfactorybean factory = new clientproxyfactorybean ();
- Factory. setserviceclass (testservice. Class );
- Factory. setaddress ("http: // localhost: 8080/apm_cxf/services/test ");
- Testservice service = (testservice) Factory. Create ();
- System. Out. println (service. sayhello ());
- }
- }
Testserviceimpl. Java
- Package JP. co. APM. Service. impl;
- Import JP. co. APM. Service. testservice;
- Public class testserviceimpl implements testservice {
- Public String sayhello (){
- Return "Hello, Shen Bin ";
- }
- }
Testservice. Java
- Package JP. co. APM. Service;
- Public interface testservice {
- Public String sayhello ();
- }
Cxf-servlet.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: simple = "http://cxf.apache.org/simple"
- Xmlns: Soap = "http://cxf.apache.org/bindings/soap"
- Xsi: schemalocation ="
- Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- Http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
- Http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd ">
- <Simple: Server id = "testservice" serviceclass = "JP. co. APM. Service. testservice" address = "/test">
- <Simple: servicebean>
- <Bean class = "JP. co. APM. Service. impl. testserviceimpl"/>
- </Simple: servicebean>
- </Simple: Server>
- </Beans>
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>
- <Display-Name> APM </display-Name>
- <Description> APM </description>
- <Servlet>
- <Servlet-Name> APM </servlet-Name>
- <Servlet-class>
- Org. Apache. cxf. Transport. servlet. cxfservlet
- </Servlet-class>
- <Load-on-startup> 2 </load-on-startup>
- </Servlet>
- <Servlet-mapping>
- <Servlet-Name> APM </servlet-Name>
- <URL-pattern>/services/* </url-pattern>
- </Servlet-mapping>
- <Session-config>
- <Session-Timeout> 60 </session-Timeout>
- </Session-config>
- </Web-app>
Start Tomcat and access http: // localhost: 8080/apm_cxf/services/test? WSDL
Run testserviceclient. Java to test the result.