使用HessianServiceExporter提供bean服务
根据上面的描述,必须提供remoting-servlet.xml文件。通常,在remoting-servlet.xml文件里定义Hessian服务即可。Spring使用HessianServiceExporter,将一个常规bean导出成Hessian服务。类似于RmiServiceExporter,HessianServiceExporter可将一个普通bean导出成远程服务。remoting-servlet.xml的详细配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Spring配置文件的文件头,包含dtd信息-->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 定义普通bean实例-->
<bean id="helloService" class="lee.HelloImpl"/>
<!-- 使用HessianServiceExporter 将普通bean导出成Hessian服务-->
<bean name="/helloService" class="org.springframework.remoting.caucho.HessianServiceExporter">
<!-- 需要导出的目标bean-->
<property name="service" ref="helloService"/>
<!-- Hessian服务的接口-->
<property name="serviceInterface" value="lee.Hello"/>
</bean>
</beans>