上一篇博客Hessian探究(一)Hessian入门示例我们初步简单的介绍了一下Hessian的使用入门示例,由于Spring现在使用的实在是太广泛了,接下来我们介绍一下Hessian和Spring一起开发的过程。

在上一篇博客中我们是通过如下代码来调用Hessian发布的服务:简单来说就是通过URL进行访问来使用Hessian发布的服务。

package com.tianjunwei.hessian.client;

import java.net.MalformedURLException;

import com.caucho.hessian.client.HessianProxyFactory;
import com.tianjunwei.hessian.server.HelloService;

public class HelloServiceMain {

	public static void main(String [] args) throws MalformedURLException{
		String url = "http://localhost:8080/hessian";
	    System.out.println(url);
	    HessianProxyFactory factory = new HessianProxyFactory();
	    HelloService helloService = (HelloService) factory.create(HelloService.class, url);
	    System.out.println(helloService.helloWorld("jimmy"));
	}

}

在Spring下我们又是如何来使用Hessian的服务端来发布的服务的。

(1)Hessian给我们提供了在Spring下使用的HessianProxyFactoryBean,其实就是一个代理工厂,生成代理类。在spring的ApplicationContext.xml中进行如下配置,其实就是两个信息serviceUrl为Hessian暴露服务的连接,serviceInterface为暴露服务的接口。

<!-- 客户端Hessian代理工厂Bean -->
    <bean id="clientSpring" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
    	<!-- 服务端请求地址 -->
        <property name="serviceUrl">
	<span style="white-space:pre">	</span><value>http://localhost:8080/hessian</value>
        </property>
        <!-- 接口定义 -->
        <property name="serviceInterface">
            <span style="white-space:pre">	</span><value>com.tianjunwei.hessian.server.HelloService</value>
        </property>
    </bean>  

(2)经过第一步配置之后,接下来我们就可以在Spring中像使用普通的Bean一样来进行远程调用了,示例代码如下:

package com.tianjunwei.hessian.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.tianjunwei.hessian.server.HelloService;

public class SpringClient {

	    public static void main(String[] args) {
	        ApplicationContext contex = new ClassPathXmlApplicationContext(
	                "applicationContext.xml");
	        // 获得客户端的Hessian代理工厂bean
	        HelloService helloService = (HelloService) contex.getBean("clientSpring");
	        System.out.println(helloService.helloWorld("world"));
	    }
}

运行结果:

hello,world

Hessian探究(一)Hessian与Spring结合的更多相关文章

  1. Hessian探究(一)Hessian与springMVC结合

    上一篇博客Hessian探究(一)Hessian入门示例我们初步简单的介绍了一下Hessian的使用入门示例,我们是通过Servlet来暴露Hessian的对外服务的,接下来我们介绍一下通过Sprin ...

  2. Hessian Servlet和Hessian Spring的简单应用

    转自: http://lancui.iteye.com/blog/935578 简介 相比WebService,Hessian更简单.快捷.采用的是二进制RPC协议(Binary),因为采用的是二进制 ...

  3. Hessian探究(一)Hessian入门示例

    一.hessian的maven信息: [html] view plain copy print? <dependency> <groupId>com.caucho</gr ...

  4. java深入探究12-框架之Spring

    1.引入Spring 我们在搭建框架时常常会解决问题:对象创建,对象之间依赖关系如何处理,Spring就是来解决这类问题的:控制反转依赖注入 2.环境搭建 1)下载源码:其中3.0以下版本源码中有Sp ...

  5. Spring整合Hessian

    Spring让Hessian变得不但强大,而且易用,但是易用背后,却有不少陷阱!   这个例子很简单,但实际上的确花费了我超过一小时的时间,排除了种种问题,最后问题终于水落石出.   整合以上篇Hel ...

  6. spring mvc 结合 Hessian 配置

    spring mvc 结合 Hessian 配置 1.先在web.xml中配置 <!-- Hessian配置 --> <servlet> <servlet-name> ...

  7. spring集成Hessian的基本使用方法

    一.什么是RPC RPC全称Remote Procedure Call,中文名叫远程过程调用.RPC是一种远程调用技术,用于不同系统之间的远程相互调用.其在分布式系统中应用十分广泛. 二.什么是Hes ...

  8. hessian的简单使用以及与spring整合

    Hessian是一个由Caucho Technology开发的轻量级二进制RPC协议.和其他Web服务的实现框架不同的是,Hessian是一个使用二进制格式传输的Web服务协议的框架,相对传统soap ...

  9. hessian+spring集成应用

    注意事项 ▲JAVA服务器端必须具备以下几点:---->包含Hessian的jar包---->设计一个接口,用来给客户端调用---->实现该接口的功能---->配置web.xm ...

随机推荐

  1. python txt文件的写入和读取

    1.文件的打开 使用open () 函数 打开文件.他有两个参数,文件路径或文件名和文件的打开方式. "r" 只读模式,不能编辑和删除文件内容. "w" 写入模 ...

  2. nginx负载均衡及详细配置

    接上篇nginx配置,然后再准备两台web服务器: nginx服务器:192.168.0.241 web1:192.168.0.141 web2:192.168.0.142 一.两台web服务器先安装 ...

  3. 安装插件出现eclipse An internal error occurred during: "Installing Software". xxxxxxxxx

    就是你自己本来就有那个插件了 百度怎么删吧.... 看一下我这个文章 强烈建议本地安装的时候用第四种安装 http://www.cnblogs.com/ydymz/articles/7203260.h ...

  4. 去掉textarea和input在ios下默认出现的圆角

    -webkit-appearance:none;/*清除ios默认圆角*/ border-radius:0;

  5. JS运行机制之 Event Loop 的思考

    先举个栗子,如下: for (var i = 0; i < 5; i++) { setTimeout(function() { console.log('i: ',i); //一秒之后输出几乎没 ...

  6. lvs+keepalive实现双主模式(采用DR),同时实现TCP和UDP检测实现非web端的负载均衡,同时实现跨网段的通讯

    因为公司领导需要,需要把lvs备机也使用上,故! 使用双主,相互是主的同时也相互是备机.本人用nat测试发现RS无法实现负载均衡,故采用DR模式来实现非web端的负载均衡 lvs1: DIP 10.6 ...

  7. css文本超出省略号

    终于完成了项目了,今天我就分享自己在项目中比较实用的一些功能的实现,第一个就是纯css文本超出省略号 /* 文本单行超出省略号 */ .textels { overflow: hidden; text ...

  8. Jupyter Notebook

    Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言.在本文中,我们将介绍 Jupyter notebook 的主要特性,以 ...

  9. Go 语言基础语法

    Go 标记 Go 程序可以由多个标记组成,可以是关键字,标识符,常量,字符串,符号.如以下 GO 语句由 6 个标记组成: fmt.Println("Hello, World!") ...

  10. CommonsChunkPlugin相关

    参考https://webpack.js.org/guides/caching/#deterministic-hashes var path = require("path"); ...