2012-04-05 101 views
0

我在Spring MVC項目中使用Hessian。我創建服務器端實現,然後想要配置客戶端。客戶端可以使用代碼來配置客戶端的初始化。所使用的URL現在在代碼中被硬編碼了,但是我想將這個服務連接成一個Spring bean,以便使用@Autowired註釋處理代碼端配置。如何使用xml配置在Spring MVC上配置Hessian?

如何做到這一點?所有的幫助表示讚賞。

回答

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允許您配置各種其他功能,如安全性和超時。