欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Axis2+Spring

程序员文章站 2024-01-02 09:56:52
...

Axis2整合Spring

1、jar包

   1.1、axis2的jar包

 

<!-- axis2 -->
		<dependency>
			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2</artifactId>
			<version>1.6.2</version>
		</dependency>
		<dependency>
		    <groupId>org.apache.axis2</groupId>
		    <artifactId>axis2-spring</artifactId>
		    <version>1.6.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2-transport-http</artifactId>
			<version>1.6.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2-transport-local</artifactId>
			<version>1.6.2</version>
		</dependency>

 
   1.2、spring相关jar包

 

 

<!-- spring -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.version}</version>
			<scope>test</scope>
		</dependency>
		
		<dependency>
	      <groupId>org.springframework</groupId>
	      <artifactId>spring-context-support</artifactId>
	      <version>${spring.version}</version>
	    </dependency>

 

 

2、创建服务端

   2.1、创建接口

 

package com.tzz.ws.axis.service;

public interface AxisHelloWorld {
	public String getMessage(String message);
}

   2.3、实现类

 

 

package com.tzz.ws.axis.service.impl;

import com.tzz.ws.axis.service.AxisHelloWorld;

public class AxisHelloWorldImpl implements AxisHelloWorld {

	@Override
	public String getMessage(String message) {
		return "---------Axis Server-------" + message;
	}
}

3、配置服务端

 

   3.1、服务端的spring配置文件applicationContext.xm

 

	<bean id="axisHelloWorldService" class="com.tzz.ws.axis.service.impl.AxisHelloWorldImpl" />
	<bean id="applicationContext" class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />

  3.2、配置services.xm

在/WEB-INF目录下建立目/services/axis/(这个名字可以随便取)
然后建立在其下META-INF目录,然后再在其目录下建立services.xml 

 

<?xml version="1.0" encoding="UTF-8"?>
<service name="axisHelloWorld">
	<parameter name="ServiceObjectSupplier">
		org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
	</parameter>
	<parameter name="load-on-startup">true</parameter>
	<parameter name="SpringBeanName">axisHelloWorldService</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>

   3.2、配置web.xm

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>web-demo</display-name>

	<!-- 配置contextConfigLocation 通过上下文参数指定spring配置文件的位置 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

	<!-- 配置ContextLoaderListener 保证服务启动时完成spring初始化 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

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

 4、测试:

浏览器输入:http://localhost:8080/web-demo/services/axisHelloWorld?wsdl

 

上一篇:

下一篇: