问题
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?
回答1:
As far I remember there is no standard annotation based RMI support from spring. I came across this link (its in Thai) which briefs about creating a custom annotation which can be use within spring container environment.
回答2:
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();
}
来源:https://stackoverflow.com/questions/11138207/spring-rmi-remoting-annotation-configuration