动态创建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");

你可能感兴趣的:(spring)