Spring Hessian配置使用

Spring 提供简便的远程调用服务

一、下载hessian.jar包

二、服务器端配置

1、新建applicationContext-hessianServer.xml

<?xml version="1.0" encoding="UTF-8"?>

略....


<description>Hessian Configer</description>


<!--辅助类 可以不添加 -->

<bean id="lazySerializer" class="com.cmmb.mall.util.hessian.LazyHibernateSerializerFactory"></bean> 


<!--merchantServiceExporter 暴露服务名 -->

<bean name="merchantServiceExporter" class="org.springframework.remoting.caucho.HessianServiceExporter">

<property name="service" ref="merchantService" />

<property name="serviceInterface" value="com.ws.api.MerchantService" />

<property name="serializerFactory" ref="lazySerializer"></property>  

</bean>

<bean id="merchantService" class="com.ws.impl.MerchantServiceImpl" />

2、web.xml配置

<servlet>

  <!--merchantServiceExporter 暴露服务名 相对应 -- >

<servlet-name>merchantServiceExporter</servlet-name>

<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet

</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>merchantServiceExporter</servlet-name>

<url-pattern>/remoting/MerchantService</url-pattern>

</servlet-mapping>

三、客户端配置

1、新建applicationContext-hessianClient.xml

<?xml version="1.0" encoding="UTF-8"?>

略........

<bean id="merchantService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">

<property name="serviceUrl" value="http://192.168.1.117:8080/merchantmanage/remoting/MerchantService" />

<property name="serviceInterface" value="com.cmmb.mall.ws.api.MerchantService" />

</bean>

四、测试

pubilc class Test{

 //merchantService 配置的bean


ThirdProductService thirdProductService = (ThirdProductService) ac.getBean(" merchantService ");

public static void main(String[] args) {

//调用远程接口

List<ThirdProduct> tps =  thirdProductService.listByStatus("ONLINE");

}

}


------------------------------------------------------------------------------


辅助类:


public class LazyHibernateSerializerFactory extends SerializerFactory {

public static String versionString = "3";


@SuppressWarnings("unchecked")

@Override

public Serializer getSerializer(Class cls) throws HessianProtocolException {

try {

if (versionString.startsWith("3")

&& Class.forName(

"org.hibernate.collection.PersistentCollection")

.isAssignableFrom(cls)) {


return new LazySerializerForHibernate3(cls);

} else if (versionString.startsWith("4")

&& Class

.forName(

"org.hibernate.collection.spi.PersistentCollection")

.isAssignableFrom(cls)) {

return new LazySerializerForHibernate4(cls);

}

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return super.getSerializer(cls);

}

public static void main(String[] args) {

org.hibernate.engine.VersionValue hVersion ;

System.out.println(org.hibernate.engine.VersionValue.NEGATIVE);

}

}

http://www.eshow365.cn

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值