Setting Up the Client
On the client side, you need to create an instance of a HessianProxyFactoryBean that points to your service URL:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.devx.hessian.client" />
<bean id="personService"
class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://0.0.0.0:8080/remoting/PersonService" />
<property name="serviceInterface" value="com.dexv.hessian.IPersonService" />
</bean>
</beans>
When your service URL is defined, you can just inject the HessianProxyFactoryBean instance into your client application using regular dependency injection:
@Component("mainClient")
public class MainClient {
private IPersonService service = null;
@Autowired
public void setPersonService(@Qualifier("personService") IPersonService service) {
this.service = service;
}
}
Spring 2.5 and Hessian 2 Incompatibility Alert
As of version 3.2.0, the Hessian library started using a new version of the protocol called simply Hessian 2. Unfortunately, the current production version of Spring (namely 2.5.6.SEC01) has support for the original Hessian protocol only. Therefore, if you are on Spring 2.5, the version of Hessian that you should download is 3.1.6.
Fortunately, this has been corrected in the latest milestone builds of Spring 3.0. The code samples attached to this article use the latest Hessian 4.0.1 and Spring 3.0 M4 builds.