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

港控/mmm° 2023-10-08 16:24 81阅读 0赞

在升级了springboot2.7之后的版本,突然出现了问题,说是循环引用了,这个在之前的逻辑中确实出现了互相引用service的问题,但是修改的话,改动太大所以直接就开启了。

  1. application.yml放在spring下面
  2. main:
  3. allow-bean-definition-overriding: true
  4. allow-circular-references: true

2.6.0后关闭了循环引用,需要开启

  1. 报错信息:
  2. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '*****.BasicCompanyFourInfoController':
  3. Unsatisfied dependency expressed through field 'loginFacade'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
  4. Error creating bean with name '*****.protection.application.service.impl.LoginFacadeImpl': Unsatisfied dependency expressed through field 'checkTaskService';
  5. nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '*****.protection.domain.operation.impl.CheckTaskServiceImpl':
  6. Unsatisfied dependency expressed through field 'checkPlanService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
  7. Error creating bean with name '*****.protection.domain.operation.impl.CheckPlanServiceImpl': Unsatisfied dependency expressed through field 'checkTaskService';
  8. nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name '*****.protection.domain.operation.impl.CheckTaskServiceImpl':
  9. Requested bean is currently in creation: Is there an unresolvable circular reference?

然后spring提示:

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

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

发表评论

表情:
评论列表 (有 0 条评论,81人围观)

还没有评论,来说两句吧...

相关阅读

    相关 idea的依赖问题

    idea中maven里的Dependencies 中出现依赖的jar包都有红色下划线 可能情况: 检查本地的maven库中有对应的包,那就是依赖有问题,idea没有在本地找