server端的web.xml
<servlet>
<servlet-name>remote</servlet-name>
<!-- 使用Spring的代理Servlet -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-context.xml,
classpath:spring-hibernate.xml,
classpath:remote-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>remote</servlet-name>
<url-pattern>/remote/*</url-pattern>
</servlet-mapping>
remote-servlet.xml
<bean name="/curd" class="org.springframework.remoting.caucho.HessianServiceExporter">
<!-- service引用具体的实现-->
<property name="service" ref="dbLogicImpl" />
<property name="serviceInterface" value="com.csair.prcmapp.interfaces.DbLogic" />
</bean>
remote-client.xml
<bean id="dbLogic" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<!-- 请求代理Servlet路径 -->
<property name="serviceUrl">
<value>${remote.hessian.url}/curd</value>
</property>
<!-- 接口定义 -->
<property name="serviceInterface">
<value>com.csair.prcmapp.interfaces.DbLogic</value>
</property>
<property name="proxyFactory" ref="hessianProxyFactory" />
</bean>
在使用hessian中遇到初次启动服务端和客户端的时候连接交互没有问题,服务器半小时左右不动不访问之后,再进行访问的时候首次连接时间很长,设置超时之后就报Caused by: org.springframework.remoting.RemoteConnectFailureException: Cannot connect to Hessian remote service at [http://127.0.0.1:8080/remote/curd]; nested exception is com.caucho.hessian.client.HessianConnectionException: 500: java.net.SocketTimeoutException: Read timed out.