因为我用spring管理bean,所以要先在web.xml配置相关信息
[!-- spring listener --]
[listener]
[listener-class]org.springframework.web.context.ContextLoaderListener[/listener-class]
[/listener]
[!-- server: RemoteService Hessian config file --]
[servlet]
[servlet-name]remote[/servlet-name]
[servlet-class]org.springframework.web.servlet.DispatcherServlet[/servlet-class]
[load-on-startup]2[/load-on-startup]
[/servlet]
通过DispatcherServlet,我们把含remote的来访URL交给hessian处理
[servlet-mapping]
[servlet-name]remote[/servlet-name]
[url-pattern]/remote/*[/url-pattern]
[/servlet-mapping]
另外我们单独配置了一个remote-servlet.xml,注意看下面的
[context-param]
[param-name]contextConfigLocation[/param-name]
[param-value]/WEB-INF/applicationContext.xml[/param-value]
[!-- [param-value]/WEB-INF/remote-servlet.xml[/param-value]--]
[/context-param]
我把这个文件在web.xml里的配置注释掉了,照样起作用,这是因为spring的web包默认要读取这个文件,当然不一定要命名为remote-servlet.xml,spring会按照一定的命名规范读取相应的文件的,以下是我的remote-servlet.xml的配置:
[beans]
[description]server properties[/description]
远程调用的实现类
[bean id="myService"
class="org.wsw.framework.remoteservice.imp.MyServiceImpl"]
[property name="actCodeService"]
[ref local="sysActCodeServiceServerSide" /]
[/property]
[property name="courseItemPersonalDAO"]
[ref bean="courseItemPersonalDAO" /]
[/property]
[/bean]
[!--InsertServiceSysActCode--]
[bean id="sysActCodeServiceServerSide"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"]
[property name="transactionManager"]
[ref bean="transactionMgr"/]
[/property]
[property name="target"]
[ref local="sysActCodeTargetServerSide" /]
[/property]
[property name="transactionAttributes"]
[props]
[prop key="get*"]PROPAGATION_REQUIRED[/prop]
[prop key="add*"]PROPAGATION_REQUIRED[/prop]
[prop key="update*"]PROPAGATION_REQUIRED[/prop]
[prop key="delete*"]PROPAGATION_REQUIRED[/prop]
[prop key="create*"]PROPAGATION_REQUIRED[/prop]
[prop key="find*"]PROPAGATION_REQUIRED[/prop]
[/props]
[/property]
[/bean]
[bean id="sysActCodeTargetServerSide"
class="org.wsw.service.spring.SysActCodeServiceSpringImplServerSide"]
[property name="baseDao"]
[ref local="sysActCodeDaoServerSide" /]
[/property]
[/bean]
[bean id="sysActCodeDaoServerSide"
class="org.wsw.service.dao.hibernate.SysActCodeDaoImpl"]
[property name="sessionFactory"]
[ref bean="sessionFactory"/]
[/property]
[/bean]
远程调用的接口,注意这里bean的name属性,当然要是用burlap,用BurlapServiceExplorter
[bean name="/remoteService"
class="org.springframework.remoting.caucho.HessianServiceExporter"]
[property name="service"]
[ref local="myService"/]
[/property]
[property name="serviceInterface"]
[value]
org.wsw.framework.remoteservice.MyService
[/value]
[/property]
[/bean]
[/beans]