8

I'm trying to migrate Spring from XmlApplicationContext to AnnotationConfigApplicationContext (more info: Java-based container configuration).

Everything works perfectly but I don't know how to create a HttpInvoker client. The XML configuration is as follows:

<bean id="httpInvokerProxy" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    <property name="serviceUrl" value="http://remotehost:8080/remoting/AccountService"/>
    <property name="serviceInterface" value="example.AccountService"/>
</bean>

How should the Java Configuration look? Do I still need this Factory Bean? I think one should be able to instantiate the client without this wrapper with this configuration method.

This (somehow) feels bad to me:

public @Bean AccountService httpInvokerProxy() {
    HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
    proxy.setServiceInterface(AccountService.class);
    proxy.setServiceUrl("http://remotehost:8080/remoting/AccountService");
    proxy.afterPropertiesSet();
    return (AccountService) proxy.getObject();
}
Reporter
  • 3,897
  • 5
  • 33
  • 47
Mike Minicki
  • 8,216
  • 11
  • 39
  • 43

1 Answers1

8

Actually, the correct (and equivalent) version would be the even more awkward:

public @Bean HttpInvokerProxyFactoryBean httpInvokerProxy() {
    HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
    proxy.setServiceInterface(AccountService.class);
    proxy.setServiceUrl("http://remotehost:8080/remoting/AccountService");
    return proxy;
}

(After all you usually want the FactoryBean to be managed by Spring, not the Bean it returns)

See this recent article for reference:

What's a FactoryBean?

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588