【发布时间】:2016-06-23 12:50:23
【问题描述】:
我正在尝试将 spring 远程处理与我现有的 spring bean 集成,但似乎 spring 没有启动 RMI 服务器。我已经按照文档中的描述完成了必要的配置,但似乎它对 RMI 没有做任何事情。这是我运行 main 方法时的日志。
2016 年 6 月 23 日下午 6:07:59 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh 信息:刷新 org.springframework.context.support.ClassPathXmlApplicationContext@180bc464:启动日期 [Thu Jun 23 18:07:59 IST 2016];上下文层次的根 2016 年 6 月 23 日下午 6:07:59 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息:从类路径资源 [rmi-config.xml] 加载 XML bean 定义
在此之后,Java 进程终止。我在这里看不到任何与 RMI 相关的事情。
Rmi-config.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd" default-lazy-init="true">
<bean id="validatorServiceBean" class="com.xyz.validator.service.impl.ValidatorServiceBean">
<!-- any additional properties, maybe a DAO? -->
</bean>
<!-- RMI Server Declaration -->
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<!-- serviceName represents RMI Service Name -->
<property name="serviceName" value="ValidatorServiceBean"/>
<!-- service represents RMI Object(RMI Service Impl) -->
<property name="service" ref="validatorServiceBean"/>
<!-- serviceInterface represents RMI Service Interface exposed -->
<property name="serviceInterface" value="com.xyz.validator.service.ValidatorService"/>
<!-- defaults to 1099 -->
<property name="registryPort" value="1009"/>
</bean>
</beans>
我的客户代码:
public class RMIServerStarter {
public static void main(String[] args) throws RemoteException {
//RMI Server Application Context is started...
new ClassPathXmlApplicationContext("rmi-config.xml");
Registry registry = LocateRegistry.getRegistry("localhost", 1009);
for (String name : registry.list()) {
System.out.println(name);
}
}
}
【问题讨论】: