Spring integrates the cxf framework and springcxf framework

Source: Internet
Author: User

Spring integrates the cxf framework and springcxf framework

CXF is a webService framework that can be seamlessly integrated with spring.

# Write on the server

1. Create a dynamic web project

2. Import cxf and spring jar packages (CXF core package: cxf-2.4.2.jar)

3. Configure the core Servlet of the cxf framework in web. xml

 1 <servlet> 2       <servlet-name>cxf</servlet-name> 3       <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> 4       <init-param> 5           <param-name>config-location</param-name> 6           <param-value>classpath:applicationContext.xml</param-value> 7       </init-param> 8   </servlet> 9   <servlet-mapping>10       <servlet-name>cxf</servlet-name>11       <url-pattern>/webservice/*</url-pattern>12   </servlet-mapping>

4. The spring framework configuration file applicationContext. xml is provided.

Restrictions on applicationContext. xml:

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"xmlns:soap="http://cxf.apache.org/bindings/soap"xsi:schemaLocation="http://www.springframework.org/schema/beans                     http://www.springframework.org/schema/beans/spring-beans.xsd                    http://cxf.apache.org/bindings/soap                     http://cxf.apache.org/schemas/configuration/soap.xsd                    http://cxf.apache.org/jaxws                     http://cxf.apache.org/schemas/jaxws.xsd">

5. Develop a service class

Note: The service class must be annotated with @ WebService

6. register the service in the spring configuration file

<Jaxws: endpoint id = "" address = "/hello" implementor = ""> </jaxws: endpoint> <! -- Id is the service id, and any address that is the access address implementor is the full Class Name of the service class -->

Start the web Project and access it through a browser

 

### Client

(Use the wsdl2java command to generate a local code call)

1. Open the command window in the folder where the wsdl2java. bat command is located, and enter: wsdl2java-d. Path

(The path is the full path of the wsdl on the page after the service is published. What is the path name for service access? Wsdl). After you press enter, a folder will be generated under the current folder.

2. Copy the folder to the project.

(Use spring files to register proxy objects for calling)

1. Create a project. You can import a jar package instead of a web project.

2. Copy the generated interface to the project,

3. Create the configuration proxy object in the applicationContext. xml file.

<Jaxws: client id = "" address = "" serviceClass = ""> </jaxws: client> <! -- The id value is random. The value of adress is the path value of wsdl. If it is not on the local machine, you must modify the ip serviceClass as the full path of the interface. -->

4. Compile the implementation class (for example below)

Public static void main (String [] args) {// create the factory object ClassPathXmlApplicationContext cts = new ClassPathXmlApplicationContext ("applicationContext. xml "); Fun1 proxy = (Fun1) cts. getBean ("myclient"); String string = proxy. sayHello ("Haha", 12); System. out. println (string );}

 

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.