【发布时间】:2012-01-14 04:28:42
【问题描述】:
我有这个例外:
SEVERE: Context initialization failedorg.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'myService': Bean with name 'myService' has been injected into other beans [otherService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
任何人都可以提出好的策略来找到循环依赖的来源吗?
我目前正在查看上下文定义,但正如您可能想象的那样,在某个成熟的项目中,这需要相当长的时间。
所以我通常在寻找快速找到循环 bean 依赖项的想法。
【问题讨论】:
-
您是否在配置中使用 XML、注释或配置类?
-
这里有一篇关于解决的好文章:blog.richardadamdean.com/?p=49
-
错误信息不是在说 bean
otherService有问题吗?otherService是否有某种方式依赖于myService但myService也依赖于otherService?您是在问如何查看 bean 链接以便检测依赖关系如何循环? -
@Gray 不,它们不相互依赖。反正不是直接的,这就是我想要找到的。它可能类似于 otherService->3rdService->myservice AND myService->3rdService->otherService。
-
我最终会通过挖掘上下文找到它,但如果有人知道快速/确定的方法,我会徘徊。
标签: java spring circular-dependency