其他分享
首页 > 其他分享> > Spring循环依赖

Spring循环依赖

作者:互联网

在这里插入图片描述
引用https://blog.csdn.net/chaitoudaren/article/details/105060882
当Async在AService会报错,在BService里不会报错,需在加@Lazy

@Component
public class AService {

	@Autowired
	@Lazy
	BService BService;

	@Async
	public void test(){

	}
}

@Component
public class BService {
	@Autowired
	AService AService;
}
十月 02, 2021 7:55:29 下午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: 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 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
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 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.

标签:依赖,name,BService,Spring,AService,bean,循环,beans,version
来源: https://blog.csdn.net/weixin_47345703/article/details/120588566