<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>
这个只有配置了一个接口,不会是把所有远程调用的类都放到这个接口吧,如果有许多接口应该怎么配置?
还有客户端得配置?

解决方案 »

  1.   

    这个只有配置了一个接口,不会是把所有远程调用的类都放到这个接口吧,如果有许多接口应该怎么配置?
    --- 通常RMI不是每个service用一个接口,而是共享一个接口
      

  2.   

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

  3.   

    是的。不同的service用不同的serviceName区分。
      

  4.   

    解决办法很简单:配置多个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:  }
      

  5.   

    见 http://blog.csdn.net/xiefeifeihu/archive/2009/11/25/4871951.aspx