动态创建Spring HttpInvoker client

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");



posted @ 2011-09-14 15:33  反正我信了  阅读(1138)  评论(0编辑  收藏  举报