聊聊@Async注解遇到的问题

本文探讨了在Spring中使用@Async注解时遇到的循环依赖问题。当@Async注解的方法与循环依赖结合时,Spring无法解决,导致BeanCurrentlyInCreationException异常。@Async的生效依赖于AsyncAnnotationBeanPostProcessor,而AOP和事务处理则是由AnnotationAwareAspectJAutoProxyCreator完成。文章详细分析了Spring解决循环依赖的机制,提出了解决此类问题的四种方法,包括调整依赖关系、避免@Async、使用@Lazy和配置Spring允许原始注入。
摘要由CSDN通过智能技术生成

项目控制台发现了如下的异常信息:

Exception in thread "main" org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'AService': Bean with name 'AService' has been injected into other beans [BService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602)
 at org.springframework.beans.factory.su
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值