最近在阅读远程服务调用。在实践Spring集成Hessian过程与,遇到一个问题:
Caused by: com.caucho.hessian.client.HessianConnectionException: HessianProxy cannot connect to 'http://localhost:8080/SpringRPCServiceSpittrCauchoTechnology/spitter.service
at com.caucho.hessian.client.HessianURLConnection.sendRequest(HessianURLConnection.java:142)
at com.caucho.hessian.client.HessianProxy.sendRequest(HessianProxy.java:296)
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:171)
at com.sun.proxy.$Proxy22.getSpitter(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:251)
... 35 more
经过探索,查到了问题的所在:调用了DefaultServletHandlerConfigurer 的enable() 方法。将该方法注释掉之后就能正常运行了。
// 不要写这段代码,写上会出错
/*
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
*/
详细代码在github上: 服务端应用程序(用于发布远程服务)、客户端应用程序(调用远程服务)