如何在@Configuration bean中配置RmiProxyFactoryBean?

时间:2014-12-17 20:20:11

标签: spring

我想通过SpringRMI获取远程对象:

@Configuration
public class RMIConfigBean {

    @Bean
    public NameService nameService() {
        RmiProxyFactoryBean rmi = new RmiProxyFactoryBean();
        rmi.setServiceUrl("rmi://localhost:8000/NameService");
        rmi.setServiceInterface(NameService.class);


        return (NameService) rmi.getObject();
    }
}

但实际上rmi.getObject()返回null,因此nameService的后续注入失败。我错过了什么?谢谢!

1 个答案:

答案 0 :(得分:1)

正如M.Deinum所说,我应该先致电afterPropertiesSet