Search code examples
javaspringspring-mvchessian

How to configure Hessian on Spring MVC with xml config?


I am using Hessian in a Spring MVC project. I create server side implementation and then would like to configure the client. Client can be configured with code that uses HessianProxyFactory for the initialization of the client. The URL that is used is now hard coded in the code, but I would like to wire the service some how as a Spring bean so that the code side config would be handled with @Autowired annotation.

How to make this? All help is appreciated.


Solution

  • It is described in 20.3.3 Linking in the service on the client:

    <bean id="accountService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        <property name="serviceUrl" value="http://remotehost:8080/remoting/AccountService"/>
        <property name="serviceInterface" value="example.AccountService"/>
    </bean>
    

    Where example.AccountService is the service interface that the server implements. The client also needs that interface, but you probably know that.

    Alternatively use Java configuration:

    @Bean
    public HessianProxyFactoryBean accountService() {
        HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
        factory.setServiceUrl("http://remotehost:8080/remoting/AccountService");
        factory.setServiceInterface(AccountService.class);
        return factory;
    }
    

    Now you are capable of simply injecting:

    @Autowired
    private AccountService accountService;
    

    The HessianProxyFactoryBean allows you to configure various other features like security and timeouts.