阳光VIP

少壮不努力,老大徒伤悲。平日弗用功,自到临期悔。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

动态创建Spring HttpInvoker client

Posted on 2012-02-09 22:09  阳光VIP  阅读(222)  评论(0编辑  收藏  举报

https://jira.springsource.org/browse/SPR-4045

 

If you want to abstract the HttpInvokerProxyFactoryBean and its necessary afterPropertiesSet() and getObject() methods, you could use something like the following:

public class HttpInvokerProxyFactory<O extends Object> {

@SuppressWarnings("unchecked")
public O getProxy(String serviceUrl) {

HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();

httpInvokerProxyFactoryBean.setServiceInterface(TestService.class);

httpInvokerProxyFactoryBean.setServiceUrl(serviceUrl);

httpInvokerProxyFactoryBean.afterPropertiesSet();

return (O) httpInvokerProxyFactoryBean.getObject();

}
}

Then in your client, you would simply use the following to invoke your Spring remoting service (where MyService is the interface of your service class):

MyService myService = new HttpInvokerProxyFactory<Service>().getProxy("http://localhost:8080/remoting/MyService");