现在的位置: 首页 > 综合 > 正文

动态创建Spring HttpInvoker client

2013年08月05日 ⁄ 综合 ⁄ 共 850字 ⁄ 字号 评论关闭

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

抱歉!评论已关闭.