Spring 4.1 integrates CXF3 to implement Webservice (1)


       foreword

      There are many ways to configure the spring of cxf, and spring is being updated, and cxf has been updated all the time. Now that spring4 is very common, of course, cxf2 should be abandoned. If you use wsdl2java to generate interface classes, I do not advocate this method. If the interface you publish is deployed on another server, you even have to change the class class! Based on the principle of less code less modify, the following is my sharing.

 

Development environment: jdk7, tomcat7, spring4.1.1 , hibernate4, cxf 3.1.5 , etc.

 

Server:

1. Add the jar package of cxf

     I added webservice on the basis of the existing web project, so the jar package required for the general web environment already exists. The red box in the picture below is the new package I copied from cxf, which is the least I have tested one by one. The required jar package:


   

 

>>>Share a very good and comprehensive collection of cxf package missing errors:

http://blog.csdn.net/w1014074794/article/details/47862163  

 

 

2. Write interface classes and implementation classes

 

package com.yourpackage.webservice;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface YourService  {
    
    	@WebMethod
	public String yourMethod(yourParam...);
	
}

 

package com.yourpackage.webservice.impl;
……
import java.net.URLDecoder;
import javax.jws.WebService;

@WebService(endpointInterface = "com.yourpackage.webservice.YourService", serviceName = "YourWebService")
public class YourServiceImpl implements YourService {

    @Override
    public String yourMethod(yourParam...){
	……
    }	
}

 

3. Integrate spring to publish your interface

 

<?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-4.0.xsd
        http://cxf.apache.org/jaxws
        http://cxf.apache.org/schemas/jaxws.xsd">

	<bean id="YourWebService"
		 class="com.yourpackage.webservice.impl.YourServiceImpl">
	</bean>
	<!--#yourWebService is the same as the serviceName declared on your implementation class -->
	<!--id is the same as the bean id you declared above -->
	<!--address is the path after the cxf matching path configured on web.xml, you can call it casually, but it must be consistent when accessing -->
	<jaxws:endpoint id="YourWebService" implementor="#YourWebService"
		address="/YourService" />
</beans>    

 

 

4. Add cxf support in web.xml file

 

<!-- cxf service-->
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/ws/*</url-pattern>
    </servlet-mapping>

 

   The path can be set at will, and now the address to access the wsdl when the local server is written like this is:

 

http://localhost:8080/yourProject/ws/YourService?wsdl

 

Here /YourService after ws is the address value configured in the previous step

 

 

5. Run the server and access wsdl

 

           A document in xml format like the following figure appears, indicating that the release is successful:



  

 

So far, the interface has been released. For the method of webservice call, please see the next article:

 http://weilikk.iteye.com/blog/2317179

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326525045&siteId=291194637