reprinted from: Http://www.cnblogs.com/linjiqin/archive/2011/07/05/2098316.html1. Create a new Web project, the final project directory is as follows:
Note: This article focuses only on WebService server-side development, so com.ljq.client and com.ljq.test are negligible
2. Add the required jar
3, Interface HelloWorld
Package com.ljq.service;
Public interface HelloWorld {
public string Greeting (string name);
Public String print ();
}
4, Interface implementation class Helloworldbean
Package com.ljq.service;
public class Helloworldbean implements HelloWorld {
public string Greeting (string name) {
Return "Hello" +name;
}
Public String print () {
Return "My name Lin Yi-chin";
}
}
5, WebService class Helloworldwebservice
Package com.ljq.service;
Import Org.apache.axis2.AxisFault;
Import Org.apache.axis2.ServiceObjectSupplier;
Import Org.apache.axis2.description.AxisService;
Import Org.apache.axis2.description.Parameter;
Import Org.apache.axis2.i18n.Messages;
Import org.springframework.beans.BeansException;
Import Org.springframework.context.ApplicationContext;
Import Org.springframework.context.ApplicationContextAware;
/**
* Axis2 Spring Bean may appear not found or spring applicationcontext not found.
*
* Solution: Build your own serviceobjectsupplier, implement Interface Serviceobjectsupplier, and also implement spring's Applicationcontextaware interface
*
*
* @author Administrator
*
*/
public class Helloworldwebservice implements Serviceobjectsupplier,
Applicationcontextaware {
private static ApplicationContext ctx;
Public Object Getserviceobject (Axisservice axisservice) throws Axisfault {
Parameter springbeanname = Axisservice.getparameter ("Springbeanname");
String beanname = (string) springbeanname.getvalue ()). Trim ();
if (beanname! = null) {
if (CTX = = null)
throw new Axisfault ("ApplicationContext is null!");
if (Ctx.getbean (beanname) = = null)
throw new Axisfault ("Axis2 Can ' t find Spring Bean:" + beanname);
Return Ctx.getbean (Beanname);
} else {
throw new Axisfault (Messages.getmessage ("paramisnotspecified",
"Service_spring_beanname"));
}
}
public void Setapplicationcontext (ApplicationContext ctx)
Throws Beansexception {
This.ctx = CTX;
}
}
6. Configure the Web. xml file
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
<!--add Spring listener--
<listener>
<listener-class>
Org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!--load the spring configuration file--
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!--to register Axis2 servlet--
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>
Org.apache.axis2.transport.http.AxisServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
7, in the Web-inf directory configuration applicationcontext.xml (does not exist to create their own)
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE beans Public "-//spring//dtd bean//en"
"Http://www.springframework.org/dtd/spring-beans.dtd" >
<beans>
<bean id= "ApplicationContext"
class= "Org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder"/>
<bean id= "HelloWorld" class= "Com.ljq.service.HelloWorldBean" ></bean>
</beans>
8, in the web-inf\services\axis\meta-inf\ directory configuration services.xml (does not exist to create their own)
<?xml version= "1.0" encoding= "UTF-8"?>
<service name= "Hwwebservice" >
<description>axis2 and Spring Integration case </description>
<!--to get spring's ApplicationContext object by specifying the Springservletcontextobjectsupplier class with the Serviceobjectsupplier parameter-
<parameter name= "Serviceobjectsupplier" >
Org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
</parameter>
<!--
Springbeanname fixed cannot be changed.
HelloWorld is the ID of the implementation class registered in spring
-
<parameter name= "Springbeanname" >helloWorld</parameter>
<!--
The most notable here is the <messageReceivers> element, which is used to set the processor that handles the WebService method.
For example, the GetGreeting method has a return value, so you need to use a Rpcmessagereceiver class that can handle the input and output.
The Update method does not return a value, so you need to use the Rpcinonlymessagereceiver class that only handles the input.
-
<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>
Axis2+spring integrated into this has been developed, then the project deployed to Tomcat,
Then access via HTTP://LOCALHOST:8083/AXIS2SPRING/SERVICES/HWWEBSERVICE?WSDL
Axis2+spring Integration