Skip to content

fix: 修复 RedisCenter 循环依赖导致的启动失败(BeanCurrentlyInCreationException)#388

Open
Hungerdream wants to merge 1 commit into
sohutv:mainfrom
Hungerdream:fix/rediscenter-circular-dependency
Open

fix: 修复 RedisCenter 循环依赖导致的启动失败(BeanCurrentlyInCreationException)#388
Hungerdream wants to merge 1 commit into
sohutv:mainfrom
Hungerdream:fix/rediscenter-circular-dependency

Conversation

@Hungerdream

Copy link
Copy Markdown

关联 Issue

问题

应用启动失败,抛出:

org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'redisCenter':
Requested bean is currently in creation: Is there an unresolvable circular reference?

根因

RedisCenterImpl 上存在 @Async 注解的方法(如 findInstancePatternKeys,返回 java.util.concurrent.Future,见 RedisCenterImpl.java:912)。@Async 要求 Spring 在 bean 完全初始化之后才为其生成异步代理,导致与 MachineCenterImpl / AppScrollRestartServiceImpl 的循环依赖无法用 Spring 的“早期引用(early reference)”机制消解。

修复

MachineCenterImplAppScrollRestartServiceImplRedisCenter 的字段注入处加 @Lazy,注入懒加载代理占位符以打破循环。

修改文件:

  • cachecloud-web/src/main/java/com/sohu/cache/machine/impl/MachineCenterImpl.java
  • cachecloud-web/src/main/java/com/sohu/cache/web/service/impl/AppScrollRestartServiceImpl.java

验证

已本地编译并部署验证(profile=open),应用启动正常,不再抛出循环依赖异常。

RedisCenterImpl 含 @async 方法,导致与 MachineCenterImpl /
AppScrollRestartServiceImpl 的循环依赖无法用 Spring 早期引用机制消解。
在两个类的 RedisCenter 字段注入处加 @lazy,注入懒加载代理占位符打破循环。

关联 sohutv#387
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant