Use spring to integrate cxf to publish Web Services in web projects

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.