我有以下应用程序侦听器:
package org.mycompany.listeners;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextStartedEvent;
public class MyApplicationListener implements ApplicationListener<ContextStartedEvent> {
public MyApplicationListener() {
super();
System.out.println("Application context listener is created!");
}
/**
* {@inheritDoc}
*/
public void onApplicationEvent(final ContextStartedEvent event) {
System.out.println("Context '" + event.getApplicationContext().getDisplayName() + "' is started!");
}
}
以及以下 bean 定义:
<bean name="myApplicationListener" class="org.mycompany.listeners.MyApplicationListener" />
我可以看到 bean 是在打印来自构造函数的消息时创建的,但从未收到上下文启动事件。我错过了什么?