在运行时更改自动对象

时间:2016-05-30 13:35:28

标签: java spring spring-mvc apache-zookeeper

我有一个接口ClusterHelper和一个实现该接口的类ZKClusterHelperZooKeeperConfig是我们在其中创建zookeeper对象的实例的类。现在,在ClusterHelperFactory我们有:

@Autowired
ConfigAccessor configAccessor

@Bean
ClusterHelper clusterHelper(){

    logger.info("Returning zookeeper cluster herper");
    ZKClusterHelper zch = new ZKClusterHelper();
    zch.setZookeeper((ZooKeeperConfig)configAccessor);
    ch = zch;

    return ch;
}

我在B级自动装配。

@Autowired
ClusterHelper ch;

现在,如果我更改ZooKeeperConfig类中某些字段的值。 如何让它反映在B类自动装配的ClusterHelper中。

1 个答案:

答案 0 :(得分:1)

我认为你不需要在这里做动态autowiring。我建议你为它创建单独的服务bean,然后注入,而不是手动创建新的。

考虑到默认情况下 spring bean的范围为singleton

相关问题