Spring 4 RMI 服务器未启动
Spring 4 RMI server is not starting
我正在尝试将 spring 远程处理与我现有的 spring beans 集成,但似乎 spring 没有启动 RMI 服务器。我已经按照文档中的描述完成了必要的配置,但似乎它对 RMI.Here 没有做任何事情,当我 运行 是主要方法时的日志。
Jun 23, 2016 6:07:59 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@180bc464: startup date [Thu Jun 23 18:07:59 IST 2016]; root of context hierarchy
Jun 23, 2016 6:07:59 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [rmi-config.xml]
此后 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);
}
}
}
当我使用基于 Java 的配置时,似乎 XML 条目没有任何影响它开始工作。
@Bean
public RmiServiceExporter rmiServiceExporter() {
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setServiceName("ValidatorService");
exporter.setService(service);
exporter.setServiceInterface(ValidatorService.class);
exporter.setRegistryPort(1009);
return exporter;
}
我正在尝试将 spring 远程处理与我现有的 spring beans 集成,但似乎 spring 没有启动 RMI 服务器。我已经按照文档中的描述完成了必要的配置,但似乎它对 RMI.Here 没有做任何事情,当我 运行 是主要方法时的日志。
Jun 23, 2016 6:07:59 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@180bc464: startup date [Thu Jun 23 18:07:59 IST 2016]; root of context hierarchy Jun 23, 2016 6:07:59 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [rmi-config.xml]
此后 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);
}
}
}
当我使用基于 Java 的配置时,似乎 XML 条目没有任何影响它开始工作。
@Bean
public RmiServiceExporter rmiServiceExporter() {
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setServiceName("ValidatorService");
exporter.setService(service);
exporter.setServiceInterface(ValidatorService.class);
exporter.setRegistryPort(1009);
return exporter;
}