spring高版本循环依赖报错问题

在application.yml放在spring下面
main:
    allow-bean-definition-overriding: true
    allow-circular-references: true
2.6.0后关闭了循环引用,需要开启
报错信息:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '*****.BasicCompanyFourInfoController':
Unsatisfied dependency expressed through field 'loginFacade'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '*****.protection.application.service.impl.LoginFacadeImpl': Unsatisfied dependency expressed through field 'checkTaskService';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '*****.protection.domain.operation.impl.CheckTaskServiceImpl':
Unsatisfied dependency expressed through field 'checkPlanService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '*****.protection.domain.operation.impl.CheckPlanServiceImpl': Unsatisfied dependency expressed through field 'checkTaskService';
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name '*****.protection.domain.operation.impl.CheckTaskServiceImpl':
Requested bean is currently in creation: Is there an unresolvable circular reference?

 

 

然后spring提示:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

大概意思就是:不鼓励依赖循环引用,默认情况下禁止使用循环引用。想要开启就设置下所以设置上面的就好了。

posted @ 2022-07-07 16:45  道行太浅  阅读(2982)  评论(0编辑  收藏  举报