Reputation: 4704
I have been looking for some time for this and I can't seem to find the answer. I am using Spring RMI remoting and I would like to use annotation configuration.
Is this possible?
Upvotes: 2
Views: 3901
Reputation: 24561
As @Santosh answered, there isn't standard annotation for RMI support. But you can use standard bean annotation to register RMI beans.
Do this on service side (parameter barService is implementation of service injected by Spring -> so there needs to be such bean already registered):
@Bean
public RmiServiceExporter registerService(BarService barService) {
RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
rmiServiceExporter.setServiceName("BarService");
rmiServiceExporter.setService(barService);
rmiServiceExporter.setServiceInterface(BarService.class);
rmiServiceExporter.setRegistryPort(5000);
return rmiServiceExporter;
}
Client side:
@Bean
public BarService createBarServiceLink() {
RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
rmiProxyFactoryBean.setServiceUrl("rmi://localhost:5000/BarService");
rmiProxyFactoryBean.setServiceInterface(BarService.class);
rmiProxyFactoryBean.afterPropertiesSet();
return (BarService) rmiProxyFactoryBean.getObject();
}
Upvotes: 1