Increase CXF Dependency
<dependency> <groupId>org.apache.cxf</groupId> <artifactid>apache-cxf</ artifactid> <version>${cxf.version}</version> <type>pom</type> </ Dependency>
Creating a Service Interface
import Javax.jws.WebService; @WebService Public InterfaceHelloWorld { Publicstring Sayhi (string text);} Import Javax.jws.WebService; @WebService Public classHellowwordcontroller implements HelloWorld {/** (Non-javadoc) * * @see Com.wfj.infc.helloworld#sayhi (java.lang.String)*/ Publicstring Sayhi (string text) {//TODO auto-generated Method StubSystem. out. println ("Sayhi called"); return "Hello"+text; }}
Cxfdemo-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://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http//Cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsd" default-autowire="byname"> <import resource="Classpath:meta-inf/cxf/cxf.xml"/> <import resource="Classpath:meta-inf/cxf/cxf-servlet.xml"/> <bean id="Hello" class="Com.wangfj.product.core.controller.HellowWordController"/> <jaxws:endpoint id="HelloWorld"Implementor="#hello"address="/WEBSERVICE/HW"/></beans>
Published in WebApp
The XF provides the integration of spring and also provides the org.apache.cxf.transport.servlet.CXFServlet for publishing webservice in the Web container. The previous example adds an entire APACHE-CXF dependency, so the reference to Srping is added automatically. Just write the beans configuration file and the Web. xml file.
- Configuring Cxfservlet in Web. xml
<servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class> org.apache.cxf.transport.servlet.cxfservlet</servlet-class> </servlet> < servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/services /* </url-pattern> </servlet-mapping>
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/ web-inf/cxfdemo-beans.xml</param-value> </context-param> <listener> < listener-class>org.springframework.web.context.contextloaderlistener</listener-class > </listener>
Use CXF to write a simple instance of a Web service