admin管理员组

文章数量:1566366

项目里有用到@Async执行异步任务,但是启动时候报错:

Error creating bean with name 'asyncTask': Bean with name 'asyncTask' has been injected into other beans [productionOrderBiz] 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.

什么是循环引用

循环引用,简单的说就是,A依赖B,B依赖C,C又依赖A,这样形成了一个闭环。

解决办法

按照报错提示在引用的bean上加一个@Lazy属性。Spring的懒加载是在需要用到bean的时候,就是getBean的时候才创建,这样就不会报BeanCurrentlyInCreationException。

本文标签: 注解SpringbootAsync