The first step is to import CFX related packages download address: http://cxf.apache.org/download.html
Second Step configuration Web.xml
<!--CFX Webserivice--> <servlet> <description>apache CXF endpoint</description> <display-name>cxf</display-name> <servlet-name>cxf</servlet-name> <servlet-class> Org.apache.cxf.transport.servlet.CXFServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>cxf</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>60</session-timeout> </session-config> |
The third step joins Cfx-servlet.xml under Web-inf
<?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" xmlns:soap= "Http://cxf.apache.org/bindings/soap" Xsi:schemalocation= " Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd Http://cxf.apache.org/jaxws Http://cxf.apache.org/schemas/jaxws.xsd "> <!--; Service Interface--> <jaxws:server id= "Jaxwsservice" serviceclass= "Com.uu.service.IService" address= "/test" > <!-address release Level Two address for the service full address for/project publication name/CFX intercept address/address (CFX intercept address is configured in Web.xml tab url-pattern)--> <jaxws:serviceBean> <!--service Implementation class--> <bean class= "Com.uu.service.impl.Service"/> </jaxws:serviceBean> </jaxws:server> </beans> |
Fourth step to write interface and implementation class
IService interface
package Com.uu.service; @WebService Public Interface IService { @WebMethod String Test (@WebParam string param); } |
Service Implementation class:
package Com.uu.service.impl; Public class Quoteservice implements Iquoteservice { @Override Public String Test (string param) { return "Hello," +param; } } |
Step Fifth Unit Test
@Test Public void test3 () { Jaxwsproxyfactorybean factory = new Jaxwsproxyfactorybean (); Factory.getininterceptors (). Add (new loggingininterceptor ()); Factory.getoutinterceptors (). Add (new loggingoutinterceptor ()); Factory.setserviceclass (IService. Class); Factory.setaddress ("http://localhost:8081/project name/services/test"); IService client = (iservice) factory.create (); String msg = client.test ("Kinglo"); SYSTEM.OUT.PRINTLN (msg); } |