`

(Axis2 与Spring 集成开发)Axis2 Integration with the Spring Framework

阅读更多

有同事常常会讨论Axis2 与 Spring 的整合说网上没有找到这方面的资料,在这里我就写了一个小例子,希望对广大程序员有帮助

1.下载Axis2

   我在这里选用的axis2-1.5.4 是这个版本

   下载spring 对应的包

  这里我们选用了tomcat 作为服务器(当然jdk 5.0 以上)

 2. 使用eclipse 新建dynamicWeb 项目

  导入*axis2-1.5/lib 包的所有jar  包加入一个spring中的一个spring.jar 就可以了

 这里那包具体怎么样我就不讲了,反正全部都要

3. 在web 容器中添加spring 和 Axis2 信息 配置web.xml

 

 

<?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">
  <!-- 指定spring 配置信息 -->
	<context-param>   
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:/com/webservice/spring/conf/webservice-bean.xml</param-value>
	</context-param>     
	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	<!-- 设置axisServlet 配置信息 -->
	<servlet>
		<servlet-name>AxisServlet</servlet-name>
		<display-name>AxisServlet</display-name>
		<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
	</servlet>
	<servlet-mapping>
	    <servlet-name>AxisServlet</servlet-name>
	    <url-pattern>/services/*</url-pattern>
	</servlet-mapping>
  
  <display-name>bs_interface</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 

4. 添加业务处理类

   1)

 

package com.webservice.service;

import com.webservice.entity.UserInfo;

public interface IUserInfoService {
	
	public void add(UserInfo userInfo) throws Exception;
	
	public void delete(UserInfo userInfo) throws Exception;

}

 

   2) 写实现类

  

package com.webservice.service.impl;

import com.webservice.entity.UserInfo;
import com.webservice.service.IUserInfoService;

public class UserInfoServiceImpl implements IUserInfoService {

	@Override
	public void add(UserInfo userInfo) throws Exception {
		
		System.out.println("addition successful");

	}

	@Override
	public void delete(UserInfo userInfo) throws Exception {
		System.out.println("remove successful");

	}

}

 

 3) 添加webservice 业务类

 

package com.webservice.service.impl;

import com.webservice.entity.UserInfo;
import com.webservice.service.IUserInfoService;

/**
 * 2011-3-23
 * @author liuqing
 *
 */
public class UserInfoWebService {
	
	public void add(UserInfo userInfo) throws Exception {
		this.userInfoService.add(userInfo);
	}
	
	public void delete(UserInfo userInfo) throws Exception {
		this.userInfoService.delete(userInfo);
	}

	public IUserInfoService getUserInfoService() {
		return userInfoService;
	}
	
	public void setUserInfoService(IUserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}
	
	private IUserInfoService userInfoService;

	
}

 

  5. 配置spring 配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:aop="http://www.springframework.org/schema/aop"
	   xmlns:tx="http://www.springframework.org/schema/tx"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
	 <!-- 添加spring ApplicationContextHolder Bean 在Spring 中注入Bean 代理器 -->
	 <bean id="applicationContext" 
	    class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
	
	<!-- 添加Spring Bean 对象 -->
	<bean id="userInfoWebService" class="com.webservice.service.impl.UserInfoWebService">
		<property name="userInfoService" ref="userInfoService" />
	</bean>
	
	<bean id="userInfoService" class="com.webservice.service.impl.UserInfoServiceImpl">
	</bean>

</beans>

 

   6.在WEB-INF/services/test/META-INF/services.xml

   (注意:WEB-INF/services/test 这里的test 是什么都可以的,这里的services目录相当于tomcat 中webapp)

 

<?xml version="1.0" encoding="UTF-8"?>
<serviceGroup>
    <service name="userWebService">
        <description>SyncNotifySPService</description>
        <parameter name="ServiceObjectSupplier">
            org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
        </parameter>
        <parameter name="SpringBeanName">
            userInfoWebService
        </parameter>
        <messageReceivers>
            <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
                class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
            <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
                class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
        </messageReceivers>
    </service>
</serviceGroup>

   启动Tomcat 后输入

   http://localhost:8080/bs_interface/services/userWebService?wsdl 就OK

   userWebService.wsdl 文件内容为

  

  <?xml version="1.0" encoding="UTF-8" ?> 
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://impl.service.webservice.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ax23="http://entity.webservice.com/xsd" xmlns:ax21="http://service.webservice.com/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://impl.service.webservice.com">
  <wsdl:documentation>userWebService</wsdl:documentation> 
- <wsdl:types>
- <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://entity.webservice.com/xsd">
- <xs:complexType name="UserInfo">
- <xs:sequence>
  <xs:element minOccurs="0" name="id" nillable="true" type="xs:int" /> 
  <xs:element minOccurs="0" name="other" nillable="true" type="xs:string" /> 
  <xs:element minOccurs="0" name="password" nillable="true" type="xs:string" /> 
  <xs:element minOccurs="0" name="username" nillable="true" type="xs:string" /> 
  </xs:sequence>
  </xs:complexType>
  </xs:schema>
- <xs:schema xmlns:ax24="http://entity.webservice.com/xsd" xmlns:ax22="http://service.webservice.com/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://impl.service.webservice.com">
  <xs:import namespace="http://service.webservice.com/xsd" /> 
  <xs:import namespace="http://entity.webservice.com/xsd" /> 
- <xs:element name="setUserInfoService">
- <xs:complexType>
- <xs:sequence>
  <xs:element minOccurs="0" name="userInfoService" nillable="true" type="ax22:IUserInfoService" /> 
  </xs:sequence>
  </xs:complexType>
  </xs:element>
- <xs:element name="getUserInfoServiceResponse">
- <xs:complexType>
- <xs:sequence>
  <xs:element minOccurs="0" name="return" nillable="true" type="ax22:IUserInfoService" /> 
  </xs:sequence>
  </xs:complexType>
  </xs:element>
- <xs:complexType name="Exception">
- <xs:sequence>
  <xs:element minOccurs="0" name="Exception" nillable="true" type="xs:anyType" /> 
  </xs:sequence>
  </xs:complexType>
- <xs:element name="Exception">
- <xs:complexType>
- <xs:sequence>
  <xs:element minOccurs="0" name="Exception" nillable="true" type="ns:Exception" /> 
  </xs:sequence>
  </xs:complexType>
  </xs:element>
- <xs:element name="delete">
- <xs:complexType>
- <xs:sequence>
  <xs:element minOccurs="0" name="userInfo" nillable="true" type="ax24:UserInfo" /> 
  </xs:sequence>
  </xs:complexType>
  </xs:element>
- <xs:element name="add">
- <xs:complexType>
- <xs:sequence>
  <xs:element minOccurs="0" name="userInfo" nillable="true" type="ax24:UserInfo" /> 
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:schema>
- <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.webservice.com/xsd">
- <xs:complexType name="IUserInfoService">
  <xs:sequence /> 
  </xs:complexType>
  </xs:schema>
  </wsdl:types>
- <wsdl:message name="setUserInfoServiceRequest">
  <wsdl:part name="parameters" element="ns:setUserInfoService" /> 
  </wsdl:message>
- <wsdl:message name="deleteRequest">
  <wsdl:part name="parameters" element="ns:delete" /> 
  </wsdl:message>
- <wsdl:message name="Exception">
  <wsdl:part name="parameters" element="ns:Exception" /> 
  </wsdl:message>
- <wsdl:message name="addRequest">
  <wsdl:part name="parameters" element="ns:add" /> 
  </wsdl:message>
  <wsdl:message name="getUserInfoServiceRequest" /> 
- <wsdl:message name="getUserInfoServiceResponse">
  <wsdl:part name="parameters" element="ns:getUserInfoServiceResponse" /> 
  </wsdl:message>
- <wsdl:portType name="userWebServicePortType">
- <wsdl:operation name="setUserInfoService">
  <wsdl:input message="ns:setUserInfoServiceRequest" wsaw:Action="urn:setUserInfoService" /> 
  </wsdl:operation>
- <wsdl:operation name="delete">
  <wsdl:input message="ns:deleteRequest" wsaw:Action="urn:delete" /> 
  <wsdl:fault message="ns:Exception" name="Exception" wsaw:Action="urn:deleteException" /> 
  </wsdl:operation>
- <wsdl:operation name="add">
  <wsdl:input message="ns:addRequest" wsaw:Action="urn:add" /> 
  <wsdl:fault message="ns:Exception" name="Exception" wsaw:Action="urn:addException" /> 
  </wsdl:operation>
- <wsdl:operation name="getUserInfoService">
  <wsdl:input message="ns:getUserInfoServiceRequest" wsaw:Action="urn:getUserInfoService" /> 
  <wsdl:output message="ns:getUserInfoServiceResponse" wsaw:Action="urn:getUserInfoServiceResponse" /> 
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="userWebServiceSoap11Binding" type="ns:userWebServicePortType">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
- <wsdl:operation name="delete">
  <soap:operation soapAction="urn:delete" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:fault name="Exception">
  <soap:fault use="literal" name="Exception" /> 
  </wsdl:fault>
  </wsdl:operation>
- <wsdl:operation name="setUserInfoService">
  <soap:operation soapAction="urn:setUserInfoService" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
  </wsdl:operation>
- <wsdl:operation name="add">
  <soap:operation soapAction="urn:add" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:fault name="Exception">
  <soap:fault use="literal" name="Exception" /> 
  </wsdl:fault>
  </wsdl:operation>
- <wsdl:operation name="getUserInfoService">
  <soap:operation soapAction="urn:getUserInfoService" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:binding name="userWebServiceSoap12Binding" type="ns:userWebServicePortType">
  <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
- <wsdl:operation name="delete">
  <soap12:operation soapAction="urn:delete" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
- <wsdl:fault name="Exception">
  <soap12:fault use="literal" name="Exception" /> 
  </wsdl:fault>
  </wsdl:operation>
- <wsdl:operation name="setUserInfoService">
  <soap12:operation soapAction="urn:setUserInfoService" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
  </wsdl:operation>
- <wsdl:operation name="add">
  <soap12:operation soapAction="urn:add" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
- <wsdl:fault name="Exception">
  <soap12:fault use="literal" name="Exception" /> 
  </wsdl:fault>
  </wsdl:operation>
- <wsdl:operation name="getUserInfoService">
  <soap12:operation soapAction="urn:getUserInfoService" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap12:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:binding name="userWebServiceHttpBinding" type="ns:userWebServicePortType">
  <http:binding verb="POST" /> 
- <wsdl:operation name="delete">
  <http:operation location="userWebService/delete" /> 
- <wsdl:input>
  <mime:content type="text/xml" part="delete" /> 
  </wsdl:input>
  </wsdl:operation>
- <wsdl:operation name="setUserInfoService">
  <http:operation location="userWebService/setUserInfoService" /> 
- <wsdl:input>
  <mime:content type="text/xml" part="setUserInfoService" /> 
  </wsdl:input>
  </wsdl:operation>
- <wsdl:operation name="add">
  <http:operation location="userWebService/add" /> 
- <wsdl:input>
  <mime:content type="text/xml" part="add" /> 
  </wsdl:input>
  </wsdl:operation>
- <wsdl:operation name="getUserInfoService">
  <http:operation location="userWebService/getUserInfoService" /> 
- <wsdl:input>
  <mime:content type="text/xml" part="getUserInfoService" /> 
  </wsdl:input>
- <wsdl:output>
  <mime:content type="text/xml" part="getUserInfoService" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="userWebService">
- <wsdl:port name="userWebServiceHttpSoap11Endpoint" binding="ns:userWebServiceSoap11Binding">
  <soap:address location="http://localhost:8080/bs_interface/services/userWebService.userWebServiceHttpSoap11Endpoint/" /> 
  </wsdl:port>
- <wsdl:port name="userWebServiceHttpSoap12Endpoint" binding="ns:userWebServiceSoap12Binding">
  <soap12:address location="http://localhost:8080/bs_interface/services/userWebService.userWebServiceHttpSoap12Endpoint/" /> 
  </wsdl:port>
- <wsdl:port name="userWebServiceHttpEndpoint" binding="ns:userWebServiceHttpBinding">
  <http:address location="http://localhost:8080/bs_interface/services/userWebService.userWebServiceHttpEndpoint/" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>

  

  Spring +Axis2 集成开发就OK了(STA)

     

  

1
0
分享到:
评论

相关推荐

    axis2与spring集成

    axis2与spring的集成,在application中配置要发布的Java类,然后配置aar文件,在aar打包文件中的services.xml要嵌入 &lt;parameter name="ServiceObjectSupplier"&gt;org.apache.axis2.extensions.spring.receivers....

    Axis2与Spring整合发布多个WebService

    在IT行业中,开发Web服务是常见的任务,而Axis2和Spring框架的整合为开发者提供了强大的工具来实现这一目标。本文将深入探讨如何利用这两个技术来发布多个WebService,并着重讲解项目管理和整合过程。 首先,让我们...

    axis2+spring webservice

    标题中的“axis2+spring webservice”指的是使用Apache Axis2框架与Spring框架集成来开发Web服务。Apache Axis2是Java环境中广泛使用的Web服务引擎,它提供了高性能、灵活且可扩展的架构。Spring框架则是一个全面的...

    java webservice之axis2与spring集成(二)

    在Java Web服务开发中,Apache Axis2是一个广泛使用的SOAP(简单对象访问协议)服务框架,它为构建...对于那些想要深入了解Java Web服务开发和企业级应用集成的开发者来说,熟悉Axis2与Spring的集成是必不可少的技能。

    springboot集成axis2-1.7.9实例

    在本文中,我们将深入探讨如何将Apache Axis2与Spring Boot集成,以构建一个高效、可扩展的Web服务应用。Apache Axis2是Java平台上的一个Web服务框架,它提供了高性能、灵活的服务开发和部署机制。而Spring Boot是...

    Spring集成axis2实现webservice所用到的包

    首先,让我们理解Spring与Axis2集成的基础知识。Spring框架提供了一个服务导向架构(SOA)的支持,允许开发者轻松地创建和消费Web服务。而Axis2是Apache软件基金会的一个项目,专门用于处理Web服务的生成、部署和...

    Spring集成AXIS2的Web_service配置方法

    将 Spring 集成 AXIS2 可以实现基于 Spring 的 Web 服务配置,该配置方法可以提高开发效率和系统可维护性。 一、配置 Spring 项目 首先,需要在 Spring 项目中添加 AXIS2 的依赖项,包括 axis2-spring-1.4.1.jar ...

    Axis2集成Spring.doc

    本文档旨在介绍如何将Apache Axis2与Spring框架进行集成,以实现灵活的服务部署和管理。在实际应用中,开发者可能需要利用Spring来管理业务对象(例如POJOs),并希望通过Axis2提供这些服务。这种集成方式不仅能够...

    使用Axis2整合Spring(二)

    在本篇博文中,我们将深入探讨如何在Java Web开发中使用Apache Axis2框架与Spring框架进行集成,以实现服务端的高效管理和灵活控制。Apache Axis2是著名的Web服务引擎,而Spring则是流行的Java企业级应用框架,它们...

    axis2-spring-1.5.4.jar

    《 Axis2 与 Spring 整合详解:axis2-spring-1.5.4.jar 入门指南》 在Java Web服务开发领域,Apache Axis2 和 Spring 框架都是不可或缺的重要工具。Apache Axis2 是一个高效且可扩展的Web服务引擎,用于处理SOAP...

    axis2+spring整合实例

    标题"axis2+spring整合实例"表明了这个压缩包内容是关于如何将Apache Axis2服务框架与Spring框架进行集成的实践案例。Apache Axis2是用于构建Web服务和SOA(Service-Oriented Architecture)的高性能、灵活的开源...

    axis2 + spring3.2.0

    标题中的"axis2 + spring3.2.0"指的是在Java Web开发中,将Apache Axis2服务框架与Spring 3.2.0版本的依赖管理相结合的技术应用。Apache Axis2是一个用于构建Web服务和SOA(Service-Oriented Architecture,面向服务...

    axis 和spring 集成

    标题中的“Axis和Spring集成”指的是在Java Web开发中,将Apache Axis,一个用于构建Web服务的开源工具,与Spring框架结合使用的过程。这个主题涵盖了如何利用Spring的强大依赖注入(DI)和管理bean的能力,来增强...

    spring-axis2-test.rar_Axis2 Spring3_axis2_axis2 spring3_axis2 s

    标题中的“spring-axis2-test.rar_Axis2 Spring3_axis2_axis2 spring3_axis2 s”指的是一个关于Spring和Axis2集成的示例项目,它包含了一组用于演示如何在Spring框架中使用Apache Axis2来开发和部署Web服务的源代码...

    Axis2WebService与Spring的整合

    接下来,我们来看看Spring如何与Axis2集成。Spring通过提供Spring-WS项目来支持Web服务,但它并不直接支持Axis2。然而,我们可以通过Spring的Bean管理能力,将Axis2的服务部署和配置纳入Spring的控制范围。这可以...

    axis2整合spring

    3. **Axis2与Spring的集成模块**:使用Spring-WS模块或者Spring-AXIS2模块,这些模块提供了集成工具,帮助将Spring的bean暴露为Web服务。 4. **部署服务**:在Axis2的配置文件(如services.xml)中引用Spring上下文...

    Axis2集成Spring发布WebServices服务

    本文将详细介绍如何通过集成Axis2与Spring框架来发布WebServices服务,并提供具体的配置示例。 #### 二、Axis2与Spring集成原理 在集成Axis2与Spring的过程中,主要涉及以下几个方面: 1. **服务定义**:通过Axis2...

    axis2+spring+ibatis

    Spring还支持与其他框架的集成,如Axis2,使得Web服务的调用更加方便。 3. iBATIS:iBATIS(现在已经演变为MyBatis)是一个持久层框架,它简化了Java应用与数据库之间的交互。开发者可以通过XML或注解定义SQL查询,...

    axis2和axis2+spring发布服务指南

    3. **Axis2与Spring集成**:说明如何配置Spring应用上下文,将Spring Bean作为Axis2服务,以及如何利用Spring的IoC和AOP特性优化服务行为。 4. **创建服务**:详细步骤指导如何创建一个基于Axis2的服务,包括编写...

    axis2+spring2.5整合(webservice)

    7. **安全集成**:Spring的安全框架如Spring Security可以与Axis2集成,提供认证、授权和加密等功能,增强Web服务的安全性。 整合Axis2和Spring2.5不仅提高了开发效率,还增强了Web服务的灵活性和可维护性。这种...

Global site tag (gtag.js) - Google Analytics