【问题标题】:How to configure Hessian on Spring MVC with xml config?如何使用 xml 配置在 Spring MVC 上配置 Hessian?
【发布时间】:2012-04-05 22:15:16
【问题描述】:

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

这个怎么做?感谢所有帮助。

【问题讨论】:

    标签: java spring spring-mvc hessian


    【解决方案1】:

    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 允许您配置各种其他功能,例如安全性和超时。

    【讨论】:

      猜你喜欢
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-23
      • 1970-01-01
      相关资源
      最近更新 更多