Introduction
This tutorial describes how to handle object injection in axis2 service classes using spring framework.Sample Service Class For The Tutorial
package services; public class SimpleService { private SampleClass sampleClass; public SimpleService(SampleClass sampleClass){ this.sampleClass = sampleClass; } public String echo(String echo){ return echo; }
}
Configure pom.xml
Add maven dependancies in pom.xml
<dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-http</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-local</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-spring</artifactId> <version>1.4.1</version> </dependency> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-api</artifactId> <version>1.2.14</version> </dependency> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-impl</artifactId> <version>1.2.14</version> </dependency>
Configure web.xml
Add Following Servlet and Servlet Mappings
<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>
Configure spring.xml
Define spring bean for the Web Service Class
<bean id="simpleService" class="services.SimpleService"> <constructor-arg ref="sampleClass"/> </bean>
Configure services.xml
Define the Web Service
<service name="SimpleService"> <parameter name="ServiceClass">services.StatisticsDepartmentService</parameter> <description>SimpleService</description> <parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier </parameter> <parameter name="SpringBeanName">simpleService</parameter> <operation name="echo"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> </service>
No comments:
Post a Comment