`

Hessian与Spring的整合使用

阅读更多
        最近有个项目中需要访问第三方的 WebService 服务,因为图方便,简单就打算用 Hessian 来 交互。
        这里有以下步骤:
1. 在 WebService 端要提供给客户端访问的 公共服务接口(例如: CommentHessianService),相应的客户端 也要这个(CommentHessianService)公共服务接口。 一般的都把 服务端的CommentHessianService直接 copy丢到 客户端。  有了这个 CommentHessianService 公共服务接口,下面应该要实现具体实现服务接口里面的方法。(CommentHessianServiceImpl)。

2.公共服务接口定义好后,在服务端做好相应的配置。例如有一个对应的 Service的配置文件:
context-comment-service.xml
 
  <beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
	
	<context:annotation-config />

<bean id="commentHessianServiceImpl"class="com.service.impl.CommentHessianServiceImpl"/>
</beans>


hessian对应的 service的配置文件: remoting-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	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-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

	<!-- 使用HessianServiceExporter 将普通bean导出成Hessian服务-->
	<bean name="/hessianCommentService"
		class="org.springframework.remoting.caucho.HessianServiceExporter">
		<!-- 需要导出的目标bean-->
		<property name="service" ref="commentHessianServiceImpl" />
		<!-- Hessian服务的接口-->
		<property name="serviceInterface" value="com.service.CommentHessianService" />
	</bean>
</beans>


web.xml的配置:
<servlet>
		<display-name>spring_servlet</display-name>
		<servlet-name>springServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/classes/com/config/spring/*.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
	<servlet-name>springServlet</servlet-name>
	<url-pattern>/httpTest/*</url-pattern>
</servlet-mapping>
	
<servlet-mapping>
	<servlet-name>springServlet</servlet-name>
	<url-pattern>/hessian/*</url-pattern>
</servlet-mapping>


3. 都配置好后,运行工程,测试Hessain是否正常运行: http://localhost/test/hessian/hessianCommentService  如果页面提示 405 则成功了。

4. client的Hessian配置:(上面提到有公共服务接口 CommentHessianService,直接copy到 客户端的工程目录下) 我这边对应的配置文件内容是: context-member-service.xml
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	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-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">	<!-- DataSource -->
	
	<bean id="base-memberService"
		class="com.member.impl.MemberServiceImpl">
		
		<property name="hessianService">
			<ref bean="mHessianClient" />
		</property>
		
		<property name="memberDAO">
			<ref bean="base-memberDAO" />
		</property>
		
		
	</bean>
	
	
<bean id="myHessianClient"
		class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
		<property name="serviceUrl">
			<value>http://yourHost/test/hessian/hessianCommentService</value>
		</property>
		<property name="serviceInterface">
			<value>com.member.CommentHessianService</value>
		</property>
		<!--<property name="overloadEnabled" value="true"></property>
				 反向代理设置 
		<property name="chunkedPost" value="false"/> 
	--></bean>
</beans> 


客户端的配置比较简单,引用对服务端的配置。 
0
1
分享到:
评论

相关推荐

    Hessian与spring整合

    当我们谈论“Hessian与Spring整合”时,通常是指将Hessian作为服务通信的机制,结合Spring框架来构建分布式服务系统。这种整合有以下几个关键点: 1. **服务提供者(Service Provider)**:首先,我们需要在服务端...

    Hessian与Spring整合需要jar包

    在将Hessian与Spring进行整合时,我们需要确保引入了正确的jar包。这些jar包通常包括以下几个核心组件: 1. **Hessian库**:这是实现Hessian RPC的基础,包含了序列化和反序列化的类以及远程调用的相关接口。主要的...

    hessian与spring整合的jar包

    当我们将Hessian与Spring进行整合时,主要目标是利用Spring的依赖注入(Dependency Injection, DI)和组件管理能力来简化Hessian服务的创建和管理。以下是一些关键知识点: 1. **Spring核心模块**(spring-core-...

    hessian-demo和hessian与spring整合demo.doc

    Hessian是一个轻量级的remoting on http工具,使用简单的方法提供了RMI(Remote Method Invocation,远程方法调用)的功能。采用的是二进制RPC(Remote Procedure Call Protocol,远程过程调用协议)协议,因为采用...

    轻量级远程服务调用Hessian的入门实例和与Spring整合的实例.zip

    二、Hessian与Spring整合 Hessian与Spring的整合可以帮助我们更好地管理和控制远程服务。Spring作为一个强大的企业级应用框架,可以提供依赖注入、事务管理等特性。在整合过程中,我们可以在Spring配置文件中声明...

    Hessian(Spring集成的)的应用与研究

    Spring通过其AOP(面向切面编程)和IoC(控制反转)理念,为Hessian提供了便捷的整合方式。在Spring中,我们可以定义一个Service Bean,然后使用HessianExporter或者HessianProxyFactoryBean来暴露这个服务或者创建...

    spring整合hessian进行远程通讯

    标题中的“spring整合hessian进行远程通讯”是指在Spring框架中使用Hessian库来实现远程过程调用(RPC)。这是一个常见的技术组合,用于构建分布式系统,使得应用组件之间可以跨网络进行高效通信。 Hessian是一种二...

    spring+hessian+maven整合.zip

    在Spring整合中,我们可以使用HessianExporter来暴露服务,HessianProxyFactoryBean来创建服务客户端。 3. **Maven**:Maven的pom.xml文件定义了项目依赖、构建过程和插件设置。在这个项目中,它会管理Spring、...

    hessian+spring

    ### Hessian与Spring整合知识点详解 #### 一、Hessian简介 Hessian是一个轻量级的远程服务调用框架,其主要特点在于采用高效的二进制格式进行数据传输,这使得它非常适合处理大量的二进制数据。Hessian通过HTTP协议...

    Spring集成Hessian案例

    本案例主要关注如何将Spring与Hessian进行集成,实现远程服务调用,从而提高系统的分布式能力。 首先,我们要理解Spring的核心概念。Spring通过依赖注入(Dependency Injection, DI)和面向切面编程(Aspect-...

    spring boot整合hessian的示例

    Spring Boot 整合 Hessian 的示例 在本文中,我们将通过实例代码来介绍如何将 Hessian 集成到 Spring Boot 应用程序中。Hessian 是一个基于 RPC(Remote Procedure Call,远程过程调用)的轻量级框架,它提供了一个...

    Hessian RPC-RMI技术 整合Structs Spring Hibernate Ibatis

    本文主要讨论的是如何将Hessian RPC与RMI技术整合到Structs、Spring、Hibernate和Ibatis这四个关键的Java开发框架中,以构建一个高效、灵活的分布式应用程序。 1. **Hessian配置说明**: Hessian的配置通常涉及...

    Spring整合Hessian访问远程服务

    首先,让我们理解Spring整合Hessian的基本原理。Spring通过其强大的IoC(Inversion of Control)容器管理服务和客户端,而Hessian则提供了一种二进制的序列化方式,使得远程服务调用更为高效。整合这两者,我们可以...

    Spring整合Hessian(Maven Web工程)

    一个Spring整合Hessian的Demo,同时包含Hessian服务端与客户端。是一个Maven工程,IDE使用的Eclipse,运行前需要安装Eclipse的Maven插件。可以结合文章一起学习,地址是...

    Springmvc+Hibernate+Hessian架包整合

    在IT行业中,构建高效、可扩展的Web应用是至关重要的,而Spring MVC、Hibernate和Hessian这三大技术框架的整合可以实现这一目标。本篇将详细介绍这三个组件以及它们如何协同工作,帮助开发者构建高质量的分布式应用...

    struts2+ibatis+spring+Hessian 整合项目

    struts2+ibatis+spring+Hessian 整合项目 web项目整合,服务端用hessian协议远程调用服务端的方法,hessian是用spring代理整合,struts2+ibatis+spring的整合项目,用作学习和开发基础平台构建很有用处,工程导入...

    Spring和Hessian的整合案例

    Hessian是一个由Caucho Technology开发的轻量级二进制RPC协议,因为采用的是二进制协议,所以它很适合于发送二进制数据。 本例子使用spring 整合hessian使开发更加的容易。

    在 Spring Web Flow 项目中应用 Hessian 服务

    在Spring Web Flow项目中应用Hessian服务,是一个深入整合分布式服务和前端流程管理的重要实践。Spring Web Flow(SWF)是一个强大的MVC框架,用于构建具有复杂导航逻辑的Web应用程序,而Hessian则是一种轻量级的二...

Global site tag (gtag.js) - Google Analytics