2011-09-01 5 views
8

私はSpringをXmlApplicationContextからAnnotationConfigApplicationContext(詳細はJava-based container configuration)に移行しようとしています。SpringコンフィグレーションBeanとしてのHttpRemotingクライアント

すべては完全に機能しますが、HttpInvokerクライアントの作成方法はわかりません。 XMLの設定は次のとおりです。

<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> 

Javaの設定はどのように見えるのですか?私はまだこのFactory Beanが必要ですか?私はこの設定メソッドでこのラッパーなしでクライアントをインスタンス化できるはずだと思います。

これが(何らかの形で)私には悪い感じ:

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(); 
} 
+0

関連読書:http://blog.springsource.com/2011/08/10/beyond-the-factorybean –

答えて

8

実際には、正しい(と同等の)バージョンはもっと厄介なことになります。

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

(あなたは通常、必要なすべての後Springが管理するFactoryBean、返すBeanではありません)

What's a FactoryBean?

関連する問題