FANDOM


Introduction Edit

This tutorial describes how to handle object injection in axis2 service classes using spring framework.

Sample Service Class For The Tutorial Edit

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 Edit

Add maven dependancies in pom.xml Edit

        <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 Edit

Add Following Servlet and Servlet Mappings Edit

    <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 Edit

Define spring bean for the Web Service Class Edit

    <bean id="simpleService" class="services.SimpleService">
    <constructor-arg ref="sampleClass"/>
    </bean>

Configure services.xml Edit

Define the Web Service Edit

<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>