SpringBoot multiple InitializingBean interfaces specify the Bean initialization order problem

// Implement the InitializingBean interface and override this method (execute this method after initializing the bean)    
@Override 
public void afterPropertiesSet()

Try to write only one InitializingBean interface in a project.

If you write more than one, there will be different priorities during initialization, and problems will occur if there is a mutual dependency.

Solution:

1. @DependOn annotation (this annotation can be used when a bean needs to be initialized after another bean is initialized)

2. Write all the logic into an InitializingBean

Guess you like

Origin blog.csdn.net/xc_nostalgia/article/details/108641057