spring rmi如何配置多接口

zzxiaoma 2009-07-02 11:10:04
<bean id="someService" class="com.filess.SomeServiceImpl"/>

<bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service">
<ref bean="someService"/>
</property>
<property name="serviceName">
<value>SomeService</value>
</property>
<property name="serviceInterface">
<value>com.filess.ISomeService</value>
</property>
<property name="registryPort">
<value>9000</value>
</property>
<property name="servicePort">
<value>9001</value>
</property>
</bean>
这个只有配置了一个接口,不会是把所有远程调用的类都放到这个接口吧,如果有许多接口应该怎么配置?
还有客户端得配置?
...全文
773 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞飞狐 2009-11-25
  • 打赏
  • 举报
回复
见 http://blog.csdn.net/xiefeifeihu/archive/2009/11/25/4871951.aspx
飞飞狐 2009-11-25
  • 打赏
  • 举报
回复
解决办法很简单:配置多个RmiServiceExporter的bean,使不同的服务(属性:service)用不同的服务名(属性:serviceName)和接口(属性:serviceInterface)。给个demo就更清晰了:

1: <bean id="oper1" class="***.Oper1"></bean> 2: <bean id="rmiService_oper1" class="org.springframework.remoting.rmi.RmiServiceExporter"> 3: <property name="serviceName"> 4: <value>oper1</value> <!-- 自己设定服务名 --> 5: </property> 6: <property name="service"> 7: <ref local="oper1" /> 8: </property> 9: <property name="serviceInterface">10: <value>***.IOper1</value>11: </property>12: <property name="registryPort">13: <value>9990</value> <!-- 重新注册端口,以免与默认RMI端口冲突。 -->14: </property>15: </bean>16: 17: <bean id="oper2" class="***.Oper2"></bean>18: <bean id="rmiService" class="org.springframework.remoting.rmi.RmiServiceExporter">19: <property name="serviceName">20: <value>oper2</value> <!-- 自己设定服务名 -->21: </property>22: <property name="service">23: <ref local="oper2" />24: </property>25: <property name="serviceInterface">26: <value>***.IOper2</value>27: </property>28: <property name="registryPort">29: <value>9990</value> <!-- 重新注册端口,以免与默认RMI端口冲突。 -->30: </property>31: </bean>
service、serviceName和serviceInterface都不一样,端口可以相同。

客户端的配置也很简单了:

1: <bean id="rmiClient_oper1" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> 2: <property name="serviceUrl"> 3: <value>rmi://192.168.0.***:9990/oper1</value> 4: </property> 5: <property name="serviceInterface"> 6: <value>***.IOper1</value> 7: </property> 8: </bean> 9: <bean id="rmiClient_oper2" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">10: <property name="serviceUrl">11: <value>rmi://192.168.0.***:9990/oper2</value>12: </property>13: <property name="serviceInterface">14: <value>***.IOper2</value>15: </property>16: </bean>
main里运行:

1: public static void main(String[] args) {2: ApplicationContext ctx = new ClassPathXmlApplicationContext(3: "applicationContext-client.xml");4: IOper1 o1 = (IOper1) ctx.getBean("rmiClient_oper1");5: o1.exeuteFile();6: 7: IOper2 o2 = (IOper2) ctx.getBean("rmiClient_oper2");8: o2.printHelloWorld();9: }
一师兄 2009-07-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sgcl 的回复:]
引用 3 楼 zzxiaoma 的回复:
引用 2 楼 sgcl 的回复:
这个只有配置了一个接口,不会是把所有远程调用的类都放到这个接口吧,如果有许多接口应该怎么配置?
--- 通常RMI不是每个service用一个接口,而是共享一个接口

那你的意思是不是说rmi都放到一个接口中?

是的。不同的service用不同的serviceName区分。
[/Quote]
能不能说详细点,谢谢
一师兄 2009-07-27
  • 打赏
  • 举报
回复
有没有好的方法啊
zzxiaoma 2009-07-03
  • 打赏
  • 举报
回复
有没有好的方法啊
zzxiaoma 2009-07-02
  • 打赏
  • 举报
回复
那能不能举个多service的例子
平淡面对 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zzxiaoma 的回复:]
引用 2 楼 sgcl 的回复:
这个只有配置了一个接口,不会是把所有远程调用的类都放到这个接口吧,如果有许多接口应该怎么配置?
--- 通常RMI不是每个service用一个接口,而是共享一个接口

那你的意思是不是说rmi都放到一个接口中?
[/Quote]
是的。不同的service用不同的serviceName区分。
zzxiaoma 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sgcl 的回复:]
这个只有配置了一个接口,不会是把所有远程调用的类都放到这个接口吧,如果有许多接口应该怎么配置?
--- 通常RMI不是每个service用一个接口,而是共享一个接口
[/Quote]
那你的意思是不是说rmi都放到一个接口中?
平淡面对 2009-07-02
  • 打赏
  • 举报
回复
这个只有配置了一个接口,不会是把所有远程调用的类都放到这个接口吧,如果有许多接口应该怎么配置?
--- 通常RMI不是每个service用一个接口,而是共享一个接口
billhepeng 2009-07-02
  • 打赏
  • 举报
回复
这个不会。期待高手解决。

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧