liaozihong/SpringBoot-Learning

SpringBoot-Zookeeper-Distributed-Lock

wanyuan123 opened this issue · 1 comments

尊敬的作者,学习了你的关于Zookeeper分布式锁的实现,遇到了一个问题,想请教一下.问题是:我借鉴了你的SpringBoot-Zookeeper-Distributed-Lock这个工程,但是启动的时候有个报错:The bean 'distributedLockByZookeeper', defined in class path resource [com/yuqing/userCore/support/lock/SpringConfiguration.class], could not be registered. A bean with that name has already been defined in file [D:\code\v_1\yunSystem\yun-user\yun-user-core\target\classes\com\yuqing\userCore\support\lock\DistributedLockByZookeeper.class] and overriding is disabled.根据描述,是因为distributedLockByZookeeper这个类被重复注入了.看了源码,的确是会有两次注入,请问一下,你的解决办法是什么?是开启注入覆盖吗?

确实会有两次注入,这是我不小心在DistributedLockByZookeeper上标记了@service,导致SpringBoot对它自动注入了,去掉这个注解,在SpringConfiguration配置注入和初始化就可以了。