I am trying to integrate spring remoting with my existing spring beans but seems spring is not starting RMI server. I have done the neccessary configuration as described in the docs but seems it is doing nothing about RMI.Here are the logs when i run the main method.
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]
After this the Java process dies. I can't see anything related to RMI happening here.
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>
My client code:
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);
}
}
}
Seems XML entry doesn't have any impact when i used Java based configuration it started working.
@Bean
public RmiServiceExporter rmiServiceExporter() {
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setServiceName("ValidatorService");
exporter.setService(service);
exporter.setServiceInterface(ValidatorService.class);
exporter.setRegistryPort(1009);
return exporter;
}