【发布时间】:2011-08-09 08:38:45
【问题描述】:
我有以下 ApplicationListener:
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 是在打印来自构造函数的消息时创建的,但从未收到上下文启动事件。我错过了什么?
【问题讨论】:
-
应该有@Component注解吗?
标签: java spring listener applicationcontext