Hession实现远程调用
配置远程服务端Hessian-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" 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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 远程商品接口 -->
<bean name="/goodsService"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="goodsService" />
<property name="serviceInterface" value="com.andy.service.goods.GoodsService"></property>
</bean>
</beans>
----------------------------------------------------------------------------------------------
配置远程客户端hessian_client.properties属性值
hessian.remote_portal_url=http://localhost:8080/portal/remote
hessian.goodsService=/goodsService
配置applicationContext-hessian-client.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"
xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd "
default-lazy-init="true">
<!-- 链接远程服务 -->
<!-- 引入hessian文件属性 -->
<context:property-placeholder ignore-unresolvable="true" location="classpath*:hessian/hessian_client.properties" />
<bean id="goodsService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="${hessian.remote_portal_url}${hessian.goodsService}"/>
<property name="serviceInterface" value="com.andy.service.goods.GoodsService"/>
</bean>
</beans>
==============================================================================
保证服务端与客户端实体和服务的路径相同,比如:
均为com.andy.service.goods.GoodsService
com.andy.model.goods.Goods
调用服务Service

浙公网安备 33010602011771号