The establishment of spring web projects is no longer long-winded. Let's talk about the key steps of integration.
1. The cxf package must be imported to the project.
2. Add the following content to the Web. xml file
< Servlet > < Servlet-name > Cxf </ Servlet-name > < Display-name > Cxf</ Display-name > < Description > Apache cxf endpoint </ Description > < 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 >
3. interfaces and implementation classes for providing services
1) interfaces
PackageCN. luxh. App. ws;ImportJavax. JWS. WebService; @ WebServicePublic InterfaceCalculator {IntAdd (IntNum1,IntNum2 );}
2) implementation class
PackageCN. luxh. App. ws;ImportJavax. JWS. WebService; @ WebService (endpointinterface= "Cn. luxh. App. ws. Calculator")Public ClassCalculatorimplImplementsCalculator {@ overridePublic IntAdd (IntNum1,IntNum2 ){ReturnNum1 +Num2 ;}}
3. Add the following content to the spring configuration file:
1) First add a namespace
Xmlns: jaxws = "http://cxf.apache.org/jaxws"
And xsi: schemalocation =
Http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
2) configure the service endpoint
<Jaxws: endpointID= "Calculator"Implementor= "Cn. luxh. App. ws. calculatorimpl"Address= "/Calculator" />
4. In this simple way, you can publish a web service. It seems that cxf and spring are a perfect combination.
5. Start the web application and access: http: // localhost: 8080/cxfapp/services/calculator? You can see the description file of the WSDL. Cxfapp is the name of my web application.