Integrate Spring with axis2 and springaxis2
1. Create a project with the following structure:
2. Introduce the jar package required by the project
For details about the axis jar file, refer to this blog.
3. Configure web. xml to register axis2 Information
1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <web-app version = "2.5" 3 xmlns = "http://java.sun.com/xml/ns/javaee" 4 xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" 5 xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee 6 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 7 8 <display-name> Spring + axis2 </display-name> 9 <! -- Integrate spring --> 10 <listener> 11 <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> 12 </listener> 13 <context-param> 14 <param-name> contextConfigLocation </param-name> 15 <param-value>/WEB-INF/ config/appContext *. xml </param-value> 16 </context-param> 17 <! -- Register the servlet of axis2 --> 18 <servlet> 19 <servlet-name> AxisServlet </servlet-name> 20 <servlet-class> 21 org. apache. axis2.transport. http. axisServlet22 </servlet-class> 23 <load-on-startup> 1 </load-on-startup> 24 </servlet> 25 <servlet-mapping> 26 <servlet-name> AxisServlet </servlet-name> 27 <url-pattern>/services/* </url-pattern> 28 </servlet-mapping> 29 30 31 <welcome-file-list> 32 <welcome-file> index. jsp </welcome-file> 33 </welcome-file-list> 34 </web-app>
3. Create a Service Interface
1 package com. chinawu. service; 2/** 3*4 * @ ClassName: IWebService 5 * @ Description: webService interface Class 6 * @ author Wu Yubin 7 * @ date 09:40:19 8 * @ version 1.0 9 */10 public interface IWebService {11 public String welcome (); 12 public String getParamName (String str); 13}
4. Create a service interface implementation class
1 package com. chinawu. service; 2/** 3*4 * @ ClassName: WeService 5 * @ Description: webService implementation class 6 * @ author Wu Yubin 7 * @ date 09:41:36 8 * @ version 1.0 9 */10 public class WebService implements IWebService {11 12 public String getParamName (String str) {13 return "Incoming parameter:" + str; 14} 15 16 public String welcome () {17 return "welcome chinaWu! "; 18} 19 20}
5. Create a spring configuration file
1 <?xml version="1.0" encoding="UTF-8"?>2 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"3 "http://www.springframework.org/dtd/spring-beans.dtd">4 <beans>5 <bean id="webService" class="com.chinawu.service.WebService"></bean>6 </beans>
6. Create the axis configuration file
<?xml version="1.0" encoding="UTF-8"?><service name="WebService"> <description>Spring+axis2</description> <parameter name="ServiceClass"> com.chinawu.service.WebService </parameter> <parameter name="SpringBeanName">webService</parameter> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </messageReceivers></service>
7. Service Access
Http: // localhost/spring2axis/services/WebService? Wsdl
8. Client Interface call
Package com. chinawu. client; import javax. xml. namespace. QName; import org. apache. axis2.AxisFault; import org. apache. axis2.addressing. endpointReference; import org. apache. axis2.client. options; import org. apache. axis2.rpc. client. RPCServiceClient; public class Client {public static void main (String [] args1) throws AxisFault {EndpointReference targetEPR = new EndpointReference ("http: // localhost/spring2axis/ Services/WebService "); RPCServiceClient serviceClient = new RPCServiceClient (); Options options = serviceClient. getOptions (); options. setTo (targetEPR); QName opAddDevice = new QName ("http://service.chinawu.com", "welcome"); Object [] opGetArgs = new Object [] {}; class [] returnTypes = new Class [] {String. class}; Object [] response = serviceClient. invokeBlocking (opAddDevice, opGetArgs, returnTypes ); String result = (String) response [0]; System. out. println ("WebService-welcome-reutnInfo:" + result); opAddDevice = new QName ("http://service.chinawu.com", "getParamName"); opGetArgs = new Object [] {"Hello! "}; ReturnTypes = new Class [] {String. class}; response = serviceClient. invokeBlocking (opAddDevice, opGetArgs, returnTypes); result = (String) response [0]; System. out. println ("WebService-getParamName-reutnInfo:" + result );}}
Output result information
9. view the service list
Http: // localhost/spring2axis/services/listServices
So far spring successfully integrated axis, project source code: http://pan.baidu.com/s/1gd8BwYn
Why can't axis2 + spring release specified methods but all methods in the entire service class?
It is said that this is a bug in axis2. Is this fixed in the latest version? How can this problem be solved? Problem added: It seems that the problem occurred after adding spring transactions does not seem to be fixed.
Axis2 webservice monthly spring dependency Injection
I don't know why you need to integrate them together. One is a client generated based on the wsdl protocol, and the other is developed by spring. Select the same function as the two.