Hessian应用
hessian是一种基于二进制协议传输的分布式组件。因为基于二进制协议而不是像webservice那样,基于xml,所以传输效率会高一些。
虽然不太明白其中的原理,但用java开发的hessian在.net下也是可以调用的, 即可以说实现跨平台。这方面的例子在网上也很少,所以决定花些时间整理一下,本人对hessian的了解也很有限。
hessian有许多版本,大的版本有两个,spring2.x支持hessian3,spring3.x支持hessian4。本例子将采用ibatis2+springmvc3+spring3+hessian4开发。下面列出使用了hessian需要注意的地方。
1.实体类必须实现Serializable接口。
2.配置hessian服务端.
<!-- 使用HessianServiceExporter 将普通bean导出成Hessian服务--> <bean id="HessianRemoting" name="/HessianRemoting" ref="depService"/> <!-- Hessian服务的接口--> <property name="serviceInterface" value="com.adtech.service.DepService"/> </bean> <bean id="hessianMapping"name="code"><bean id="myServiceClient" name="code"> @Beforepublic void setUp() {context = new ClassPathXmlApplicationContext("remoting-client.xml");}@Testpublic void getAllDep() {DepService depService = (DepService) context.getBean("myServiceClient");System.out.println(depService.getAllDeps());}从上面过程可以看出,其实在spring下开发hessian服务是一件相当简单的事。