8
我試圖將Spring從XmlApplicationContext
遷移到AnnotationConfigApplicationContext
(更多信息:Java-based container configuration)。作爲Java配置Bean的Spring 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配置應該如何查看?我還需要這個工廠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();
}
相關閱讀:http://blog.springsource.com/2011/08/10/beyond-the-factorybean –