Spring Framework - @DependsOn Examples

Spring Framework 

The annotation DependsOn specifies (as it's String[] value() element) one or more beans to be loaded before this bean. We want to use this annotation when beans do not directly has references of each others but still depends on each other in some ways. Letting them initialize randomly by the Spring container might results in side effects.

public class AppConfig {

public EventPublisher eventPublisherBean() {
return new EventPublisher();

public EventListener eventListenerBean() {
return new EventListener();

public EventManager eventManagerBean() {
return new EventManager();

public static void main(String... strings) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

Original Post

See Also