spring HTTP invoker:实现远程调用

一 服务端
1.建立rmi接口文件及实现类。
2.在WEB-INF加入remote-servlet.xml文件,文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 通过Spring HttpInvoker机制暴露远程访问服务 -->
<bean id="rmiService" class="com.xxx.xxx.impl.RemoteSyncInfoImpl" />
<bean name="/remoteService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="rmiService" />
<property name="serviceInterface" value="com.xxx.xxx.IRemoteSyncInfo" />
</bean>
</beans>

3.在WEB-INF/web.xml中加入以下内容:

<!-- 配置DispatcherServlet -->
<servlet>
<servlet-name>remote</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置该Servlet随应用启动时候启动 -->
<load-on-startup>2</load-on-startup>
</servlet>

<!-- 配置DispatcherServlet映射的url -->
<servlet-mapping>
<servlet-name>remote</servlet-name>
<url-pattern>/publish/*</url-pattern>
</servlet-mapping>


二 客户端
1.定义接口(不需实现类),如果需要传递对象,则需在服务端和客户端都要有对象类并且实现序列化接口。
2.在spring的xml文件加入以下内容:
<bean id="syncInfoService"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8080/orgcode/publish/remoteService</value>
</property>
<property name="serviceInterface">
<value>com.xxx.xxx.IRemoteSyncInfo</value>
</property>
</bean>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值