Spring RMI Remoting Annotation Configuration

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

Answers (2)

luboskrnac
luboskrnac

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

Santosh
Santosh

Reputation: 17893

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.

Upvotes: 1

Related Questions