Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 1.59 KB

循环依赖类型.md

File metadata and controls

37 lines (25 loc) · 1.59 KB

循环依赖

循环依赖指的是两个或多个 Bean 之间相互持有对方的依赖,形成依赖环。

循环依赖类型

  1. 构造器循环依赖:

Error creating bean with name 'constructorA': Requested bean is currently in creation: Is there an unresolvable circular reference? ConstructorTest.java

  1. Setter 循环依赖(支持):

SetterTest.java

  1. 字段注入循环依赖:

StackOverflowError异常,本质上是一个递归调用的过程,当调用到一定深度的时候,就会抛出异常。 FieldTest.java

  1. 多例 Bean 循环依赖:

Requested bean is currently in creation: Is there an unresolvable circular reference PrototypeTest.java

  1. 代理对象循环依赖
Exception in thread "main" org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'proxyA': Bean with name 'proxyA' 
has been injected into other beans [proxyB] 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 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.

ProxyTest.java