CXF Framework Introduction and Spring integration

Source: Internet
Author: User

1, CXF framework concept Introduction

Apache CXF is an open-source WebService framework that CXF can use to build and develop WebService, which can support multiple protocols such as SOAP, Post/http, HTTP, CXF Greatly simplifies the webservice and seamlessly integrates with Spring naturally. CXF is a combination of Celtrix (ESB framework) and XFire (Webserivice), the core being Org.apache.cxf.Bus (bus), similar to spring's ApplicationContext, CXF is dependent on spring, and the other CXF the jar in the release package, if all put in Lib, need to JDK1.6 and above, otherwise the JAX-WS version inconsistency is reported. The CXF has a built-in jetty server, which is a servlet container.

2. CXF Frame features

a, with spring, servlet seamless docking, CXF framework inside the servlet container integration jetty

B, the way to support annotations to publish WebService

C, able to display a list of WebService services

D, ability to add interceptors: input interceptors, output interceptors: Input log information interceptor, output log blocker, User rights authentication Interceptor

3. Use the CXF framework to publish a webservice

Step One,

Use the CXF framework to publish WebService related jar packages that need to be imported into the CXF framework, and the CXF version referenced here is 3.1.8 to import all the jar packages in the Lib directory after the official download of the version

  Step Two,

Publish a WebService of the development language leaderboard with an interface, and write interfaces and implementation classes as follows

  

  

  Step Three,

Jaxwsserverfactorybean is a subclass of Serverfactorybean and is also a feature extension class. This class can be used to publish WebService, which must be added to the class that is being published as a service @webservice annotations, if not annotated, without errors, but will not expose any methods. The WSDL files generated using this class are more canonical and, more importantly, can be intercepted by adding interceptors, and the code is interpreted as follows:

4. Publish a WebService using the CXF framework and the Spring Framework integration

  The previous service release includes how to create a service class that is hard-coded, and whether the service class can be published using configuration, the answer is yes. This is going to be integrated with spring, and since CXF's project has already integrated spring (with spring Lib), Cxf's service is done in the spring configuration file.

Step One,

Deploy the spring environment, import CXF and spring related jar packages, and import the spring versions of 3.1.8 CXF and 4.2.3 here

  Step Two,

Write an interface and business implementation class to manipulate employee information, including methods for adding and querying employees

Package structures and classes write code such as:

  

  

   

Step Three,

Configure the Web. xml file to configure the spring listener in Web. XML to automatically assemble the configuration information for the ApplicationContext. Also configure CXF servlet information to handle webservice requests, with the following configuration information, where <url-pattern>/spring/*</url-pattern> is the filter path, see the package structure above , different packet structures are configured with different filter paths.

    

Step Four,

To configure the Applicationcontext.xml file, first add the necessary paths as follows

  

Then configure the business implementation class, which is the Enployeemanagerimpl class to provide the method. Then we configure the CXF, we need to configure three things, namely the business class interface, the business implementation class and the input and output interceptors, completed the CXF and spring integrated WebService configuration.

  

  Step Five,

Start the project and, when seen similar to the following, demonstrate that the CXF and spring Integrated services are published successfully, and publish the methods in the service, that is, the method of adding and querying employees above.

CXF Framework Introduction and Spring integration

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.