Spring RMI Remoting Annotation Configuration

浪尽此生 提交于 2019-12-10 22:15:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!