如何使用xml配置在Spring MVC上配置Hessian?

时间:2012-04-05 13:28:26

标签: java spring spring-mvc hessian

我在Spring MVC项目中使用Hessian。我创建服务器端实现,然后想配置客户端。客户端可以配置使用HessianProxyFactory进行客户端初始化的代码。现在使用的URL在代码中是硬编码的,但我想将服务连接起来作为Spring bean,以便使用@Autowired注释来处理代码端配置。

如何制作?感谢所有帮助。

1 个答案:

答案 0 :(得分:3)

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>

其中example.AccountService是服务器实现的服务接口。客户端也需要该接口,但您可能知道。

或者使用Java配置:

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

现在你可以简单地注射:

@Autowired
private AccountService accountService;

HessianProxyFactoryBean允许您配置各种其他功能,如安全性和超时。