异常信息
ERROR [main] SpringApplication: [] Application run failed
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'XxxServiceImpl': Bean with name 'XxxServiceImpl' has been injected into other beans [YyyServiceImpl] 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
原因
使用@Async产生了循环依赖,spring的三级缓存解决了循环依赖,但是使用该注解后,循环引用会产生循环依赖,看别的文章说是生成bean的时候,使用@Async生成的不再是代理
如何解决
1.使用初始化懒加载方式,在使用@Autowired注解上面加上spring提供的@Lazy(别的文章介绍的方法)
2.不要使代码层面上相互依赖,而是拓展出另外一个Service
3.不适用该注解,需要异步可以使用线程池或者开一个线程