1. First you need to create a MAVEN project "Of course a Web project"
2.pom.xml Add the following
<properties>
<cxf.version>2.2.3</cxf.version>
</properties>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
Yes, you just need to introduce these two, and then the other jars that cxf need are automatically added to the project.
3. Add in the project's Web. xml
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/cxf/*</url-pattern>
</servlet-mapping>
4. The specific code is implemented as follows:
4.1 Write an interface Ihelloservice.java
Package com.niuniu.service;
Import Javax.jws.WebService;
@WebService
Public interface Ihelloservice {
public string Wolaile (string userName);
}
4.2 Implementation of the Write interface Helloserviceimpl.java
Package Com.niuniu.service.impl;
Import Javax.jws.WebService;
Import org.springframework.stereotype.Component;
Import Com.niuniu.service.IHelloService;
@WebService (endpointinterface= "Com.niuniu.service.IHelloService", Servicename= "HelloService")
@Component
public class Helloserviceimpl implements Ihelloservice {
@Override
public string Wolaile (string userName) {
Return "Hello, Wolaile," + userName;
}
}
The 4.3 configuration files are as follows:
<?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-3.2.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-servlet.xml"/>
<jaxws:endpoint id= "HelloService" implementor= "Com.niuniu.service.impl.HelloServiceImpl" address= "/cxfservice" />
</beans>
The relevant configuration of spring is not described here.
"If you don't have a spring Web project, you can start by searching for a Web project that can run and then put the configuration in a running project."
Publish the project to Tomcat and then visit http://localhost:8080/ownweb/cxf/cxfService?wsdl to see if you can access it successfully.
"Ownweb is your project name, CXF is configured in Web. XML <url-pattern>,cxfservice is the value of address in 4.3, according to their own needs can be modified under the"
MAVEN+SPRINGMVC+CXF implementation Simple WebService small example