服務(wù)端
通過org.springframework.remoting.rmi.RmiServiceExporter來暴露接口云头,供遠(yuǎn)程來調(diào)用
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
<!--提供的服務(wù)名稱-->
<property name="serviceName" value="HelloService" />
<!--服務(wù)實(shí)現(xiàn)類引用-->
<property name="service" ref="helloServiceImpl" />
<!--暴露的服務(wù)接口-->
<property name="serviceInterface"
value="com.study.remoting.IHelloService" />
<property name="registryPort" value="8080" />
<property name="servicePort" value="8088" />
</bean>
<!--服務(wù)實(shí)現(xiàn)類對(duì)象-->
<bean id="helloServiceImpl" class="com.study.remoting.HelloServiceImpl" />
</beans>
客戶端
通過org.springframework.remoting.rmi.RmiProxyFactoryBean可以使用服務(wù)端暴露的服務(wù)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="helloService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<!--引用RMI服務(wù)的地址-->
<property name="serviceUrl" value="rmi://192.168.1.103:8080/HelloService" />
<!--服務(wù)端暴露的接口類-->
<property name="serviceInterface"
value="com.study.remoting.IHelloService" />
</bean>
</beans>
使用spring對(duì)RMI的支持乘客,可以非常容易地構(gòu)建你的分布式應(yīng)用!雹嗦!