hessian远程调用及spring中使用hessian
2016-09-26 19:24
387 查看
hessian远程调用及spring中使用hessian
官方文档:使用方法:http://hessian.caucho.com/#TheServiceAPI
序列化协议:http://hessian.caucho.com/doc/hessian-serialization.html
hessian远程调用
接口API:public interface BasicAPI { public String hello(); }
接口API实现:
public class BasicService extends HessianServlet implements BasicAPI { private String _greeting = "Hello, world"; public void setGreeting(String greeting) { _greeting = greeting; } public String hello() { return _greeting; } }
调用方式:
String url = "http://hessian.caucho.com/test/test"; HessianProxyFactory factory = new HessianProxyFactory(); BasicAPI basic = (BasicAPI) factory.create(BasicAPI.class, url); System.out.println("hello(): " + basic.hello());
另外还需要有servlet定义,这个需要自己查看HessianServlet,官方没给出,这里不说明,因为重点是spring的。
spring中使用hessian
除了上面的接口API及其实现类定义外,需要使用spring来定义。客户端配置代理类
<bean id="userLocaleService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean"> <property name="serviceUrl" value="http://127.0.0.1:8081/support/serviceUrl" /> <property name="serviceInterface" value="service.UserLocaleService" /> <property name="allowNonSerializable" value="true" /> <property name="hessian2" value="true" /> </bean>
服务端配置:
单独定义一个文件叫,spring-remote-servlet.xml文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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.xsd"> <!--userLocaleServiceImp是接口service.UserLocaleService的实现,通过注解@Service定义的--> <bean name="/userLocaleService" class="org.springframework.remoting.caucho.HessianServiceExporter"> <property name="service" ref="userLocaleServiceImp"/> <property name="serviceInterface" value="service.UserLocaleService"/> <property name="allowNonSerializable" value="true"/> </bean> </beans>
web.xml配置
<servlet> <servlet-name>spring-remote</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-remote-servlet.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>spring-remote</servlet-name> <url-pattern>/support/*</url-pattern> </servlet-mapping>
这样即可,spring只处理 /support/* 的url,访问时只需要使用 /support/userLocaleService 即可。
相关文章推荐
- Spring使用Hessian实现远程调用
- 《Spring技术内幕》学习笔记18——Spring使用Hessian实现远程调用
- 《Spring技术内幕》学习笔记18——Spring使用Hessian实现远程调用
- 《Spring技术内幕》学习笔记18——Spring使用Hessian实现远程调用
- Spring使用Hessian实现远程调用
- 《Spring技术内幕》学习笔记18——Spring使用Hessian实现远程调用
- spring技术内幕18-Spring使用Hessian实现远程调用
- 《Spring技术内幕》学习笔记18——Spring使用Hessian实现远程调用
- Spring之集成之使用Hession或Burlap通过http远程调用业务
- Spring使用远程服务之Hessian
- 使用Spring HTTP invoker进行远程调用
- Spring+Hessian搭建远程方法调用
- Spring与远程调用RMI、Hessian、Burlap、HttpInvoker、Jax-WS
- Spring远程调用技术<2>-Hessian和Burlap
- 使用SpringBoot进行远程RMI调用
- Spring + Hessian 实现轻量级分布式远程调用【包含rmi方式重构】
- 使用cxf框架搭建基于Spring远程调用Web服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- spring hessian远程调用
- Hessian远程调用框架进阶教程(一) Hessian介绍JAVA使用Hessian进行编程实例