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.
上一篇:Spring框架的常见错误


下一篇:spring成神之路第十篇:primary可以解决什么问题?