Reputation: 179
I am trying to convert my application from an xml and properties file based configuration to an annotation and java based configuration using Spring and Dropwizard. I have tried using the following client side code referring Spring RMI Remoting Annotation Configuration in my application but it gives a classcast exception.
@Bean
public BarService createBarServiceLink() {
RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
rmiProxyFactoryBean.setServiceUrl("rmi://localhost:5000/BarService");
rmiProxyFactoryBean.setServiceInterface(BarService.class);
rmiProxyFactoryBean.afterPropertiesSet();
return (BarService) rmiProxyFactoryBean.getObject();
}
The older application has BarService class not extending any other class and the entire configuration is done in xmls but it still works.
I cannot make changes on the service side as it is a different system and can only make changes at client side. Is this doable? How can I do this without touching the service side(other systems code).
Upvotes: 0
Views: 139
Reputation: 1123
See in https://www.baeldung.com/spring-remoting-rmi that your return must be:
@Bean
public RmiProxyFactoryBean createBarServiceLink() {
RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
rmiProxyFactoryBean.setServiceUrl("rmi://localhost:5000/BarService");
rmiProxyFactoryBean.setServiceInterface(BarService.class);
rmiProxyFactoryBean.afterPropertiesSet();
return rmiProxyFactoryBean;
}
On getBean() the spring known as call BarService. For example:
public static void main(String[] args) throws BookingException {
BarService service = SpringApplication
.run(RmiClient.class, args).getBean(BarService.class);
// use service
}
In this way you don't change in server or client side.
Upvotes: 1