Spring中循环依赖会产生什么问题

A依赖于B,B依赖于C,C依赖于A

<beans>
  
  <bean class="com.skr.pojo.A" name="a" depends-on="b">bean>
  
  <bean class="com.skr.pojo.B" name="b" depends-on="c">bean>
  
  <bean class="com.skr.pojo.C" name="c" depends-on="a">bean>
beans>

此时说如果让Spring容器创建A的对象就会报如下错误

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'c' defined in class path resource
[applicationContext1.xml]: Circular depends-on relationship between 'c' and 'a'

即不能创建C的实例,A和C是循环的依赖关系

你可能感兴趣的:(后端,git,vue,android,studio)