Spring高版本循环依赖报错问题
在升级了springboot2.7之后的版本,突然出现了问题,说是循环引用了,这个在之前的逻辑中确实出现了互相引用service的问题,但是修改的话,改动太大所以直接就开启了。
在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.
大概意思就是:不鼓励依赖循环引用,默认情况下禁止使用循环引用。想要开启就设置下所以设置上面的就好了。
还没有评论,来说两句吧...