我有一个接口ClusterHelper
和一个实现该接口的类ZKClusterHelper
。 ZooKeeperConfig
是我们在其中创建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
中。
答案 0 :(得分:1)
我认为你不需要在这里做动态autowiring
。我建议你为它创建单独的服务bean,然后注入,而不是手动创建新的。
考虑到默认情况下 spring bean的范围为singleton
。