spring-hessian-client.xml是hessian客户端调用的配置,可以配置多个.服务端的配置参考spring-hessian-server.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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
default-lazy-init="false">
<description>Spring hessian配置</description>
<!-- 同步传感器数据 -->
<bean id="syncMonitorAutoCollectDataService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8097/monitor/hessian/syncMonitorAutoCollectData</value>
</property>
<property name="serviceInterface">
<value>com.dzmsoft.monitor.api.service.SyncMonitorAutoCollectDataService</value>
</property>
</bean>
<!-- 同步运行日志 -->
<bean id="syncMonitorRunLogService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8097/monitor/hessian/syncMonitorRunLog</value>
</property>
<property name="serviceInterface">
<value>com.dzmsoft.monitor.api.service.SyncMonitorRunLogService</value>
</property>
</bean>
<!-- 同步维修日志 -->
<bean id="syncMonitorMaintainLogService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8097/monitor/hessian/syncMonitorMaintainLog</value>
</property>
<property name="serviceInterface">
<value>com.dzmsoft.monitor.api.service.SyncMonitorMaintainLogService</value>
</property>
</bean>
<!-- 同步入库表 -->
<bean id="syncMonitorInstockService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8097/monitor/hessian/syncMonitorInstock</value>
</property>
<property name="serviceInterface">
<value>com.dzmsoft.monitor.api.service.SyncMonitorInstockService</value>
</property>
</bean>
<!-- 同步出库表 -->
<bean id="syncMonitorOutstockService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8097/monitor/hessian/syncMonitorOutstock</value>
</property>
<property name="serviceInterface">
<value>com.dzmsoft.monitor.api.service.SyncMonitorOutstockService</value>
</property>
</bean>
<!-- 同步轮衬表单-->
<bean id="syncMonitorWheelBillService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8097/monitor/hessian/syncMonitorWheelBill</value>
</property>
<property name="serviceInterface">
<value>com.dzmsoft.monitor.api.service.SyncMonitorWheelBillService</value>
</property>
</bean>
<!-- 同步钢绳测量表单 -->
<bean id="syncMonitorWireBillService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8097/monitor/hessian/syncMonitorWireBill</value>
</property>
<property name="serviceInterface">
<value>com.dzmsoft.monitor.api.service.SyncMonitorWireBillService</value>
</property>
</bean>
<!-- 同步停车记录 -->
<bean id="syncMonitorStopCarService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8097/monitor/hessian/syncMonitorStopCar</value>
</property>
<property name="serviceInterface">
<value>com.dzmsoft.monitor.api.service.SyncMonitorStopCarService</value>
</property>
</bean>
</beans>
很多时候,服务端地址是变得,那么我们就不能总变spring-hessian-client.xml吧,除非你用disconf来管理配置文件,但是那为啥又不直接使用dubbo呢?除了配置的方式,另外一种方式,就可以写代码调用,下面是实例
@Transactional(readOnly = false)
@Override
public void sync() {
List<FontalInstock> fontalInstocks = fontalInstockService.selectNoSyncDatas();
if (!CheckEmptyUtil.isEmpty(fontalInstocks)){
String datas = gson.toJson(fontalInstocks);
String merchCode = fontalConfigService.getMerchCode();
String url = fontalConfigService.getMonitorUrl() + WorkerEnum.syncMonitorInstock.value();
String upDown = fontalConfigService.getUpDown();
//
HessianProxyFactory factory = new HessianProxyFactory();
SyncMonitorInstockService syncMonitorInstockService;
String result = null;
try {
syncMonitorInstockService = (SyncMonitorInstockService)factory.create(SyncMonitorInstockService.class,url);
result = syncMonitorInstockService.sync(datas, merchCode, upDown);
if (!CheckEmptyUtil.isEmpty(result)){
// 更改上传结果
callback(result);
}
} catch (MalformedURLException e) {
logger.error("远程调用monitor 失败,失败原因:{}",e.getMessage());
e.printStackTrace();
}
}
}