注意:1.方法參數是對象,需要改對應序列化。
2.調用接口路徑服務器端跟客戶端需保持一致。
1.hessian服務器端配置
remote-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:task="http://www.springframework.org/schema/task"
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="warnInfoService" class="com.cmsz.rc.services.impl.WarnInfoServiceImpl" />
<!-- hessionServiceExporter作用將一個常規 bean 導出成 Hessian 服務。 -->
<bean name="/logPersonHessian"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service">
<ref bean="warnInfoService" />
</property>
<property name="serviceInterface">
<value>com.cmsz.rc.services.WarnInfoService</value>
</property>
</bean>
</beans>
logPersonHessian:客戶端配置時需要配置。
warnInfoService:讓客戶端調用的的接口
serviceInterface:要調用接口對應路徑
2.客戶端配置
remote-client.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:task="http://www.springframework.org/schema/task"
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 在spring的配置文件中配置hession工廠代理類 -->
<bean id="myServiceClient"
class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://192.168.215.87:8080/RiskControl_TimingDetection/logPersonHessian
</value>
</property>
<property name="serviceInterface">
<value>com.cmsz.rc.services.WarnInfoService</value>
</property>
</bean>
</beans>
192.168.215.87:服務器端IP地址
8080:服務器端口號
logPersonHessian:服務器bean的名字
方法調用:
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:remote-client.xml");
TimeTaskHandleService iLogPerson = (TimeTaskHandleService) context.getBean("myServiceClient");
iLogPerson.方法();