maven下axis2与spring的整合开发流程

来源:互联网 发布:c 凯撒密码编程 编辑:程序博客网 时间:2024/06/09 13:45

第一步:pom.xml导入axis2的依赖  我用1.6.2版本的

<!--axis2版本指定-->

<axis2.version>1.6.2</axis2.version>

 

<!--axis2 begin-->

<dependency>

    <groupId>org.apache.axis2</groupId>

    <artifactId>axis2</artifactId>

    <version>${axis2.version}</version>

</dependency>

<dependency>

    <groupId>org.apache.axis2</groupId>

    <artifactId>axis2-spring</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-xmlbeans</artifactId>

    <version>${axis2.version}</version>

</dependency>

<!--axis2 end-->

第二步:创建要发布的接口与实现类(可以不写接口,直接实现类)

接口:


实现类:(实现类上面加上@Component注解,通过spring扫描)


第三步:修改web.xml的配置文件,添加如下内容

<!-- Axis2 -->

<servlet>

    <servlet-name>AxisServlet</servlet-name>

     <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>

    <load-on-startup>2</load-on-startup>

</servlet>

<servlet-mapping>

    <servlet-name>AxisServlet</servlet-name>

    <url-pattern>/services/*</url-pattern>

</servlet-mapping>


第四步:如果你的项目之前没有配置过spring监听器的话,需要做如下配置

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener> 


第五步:配置spring把axis2交给spring来管理



第六步:配置services.xml文件


services.xml内容如下


<?xml version="1.0" encoding="UTF-8"?>

<!-- 通过ServiceObjectSupplier参数指定SpringServletContextObjectSupplier类来获得Spring的ApplicationContext对象 -->

<service name="ServiceServer">

    <description>axis2</description>

    <!-- 通过ServiceObjectSupplier参数指定SpringServletContextObjectSupplier类来获得Spring的ApplicationContext对象 -->

    <parameter name="ServiceObjectSupplier" locked="false">

        org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier

    </parameter>

    <!--

       SpringBeanName固定的不能改

       serviceServerImplspring中注册的实现类得id,@Component注解

     -->

    <parameter name="SpringBeanName">serviceServerImpl</parameter>

    <!--

  <messageReceivers>元素,该元素用于设置处理WebService方法的处理器。

    例如,getGreeting方法有一个返回值,因此,需要使用可处理输入输出的RPCMessageReceiver类,

    update方法没有返回值,因此,需要使用只能处理输入的RPCInOnlyMessageReceiver类。

     -->

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


第七步:部署tomcat并启动服务访问

输入:http://localhost:8181/ROOT/services/ServiceServer?wsdl


传递参数:


到这里wsdl能够浏览并显示出来说明已经配置成功了。

当然如果想要可以看到服务,可以复制axis2包下的


到项目的wabapp下,然后访问:http://localhost:8082/ROOT/axis2-web/



即可看到所有提供的服务了。

整体的结构:


到这里基本的已经全部配置完毕


0 0
原创粉丝点击