How to resolve circular dependency between beans in Spring IoC?

Suppose I have a bean that depends on another bean, and another bean depends on the first bean.

Bean#1 -> Bean#2 -> Bean#1

How can I solve this problem?

+4
source share
2 answers

This is from Spring Link

In general, you can trust Spring to do the right thing. It detects configuration problems, such as links to non-existent beans and circular dependencies, when loading a container. Spring sets properties and resolves dependencies as late as possible when the beans are actually created.

Thus, it creates instances as beans and inserts them on top of each other.

EDIT

BeanCurrentlyInCreationException - . , . , , !

+8

, . , , , . , .

BeanA -> BeanB

bean, , .

BeanA -> BeanC
BeanB -> BeanC
+5

All Articles