我想在一个类中处理多个事件,这是我的例子:
@Lazy(false)
@Component
public class EventListenerImpl {
@EventListener
public void handleContextRefreshedEvent(ContextRefreshedEvent event) {
LOGGER.log(event.getSource());
...
}
}
但是,当我的应用程序启动时,此方法未执行.
在我的applicationContext.xml中,我有:
<context:annotation-config/>
<context:component-scan base-package="..."/>
根据文档,这应该足以让@EventListener工作.
实现ApplicationListener< ContextRefreshedEvent>的旧方法工作得很好.
我正在使用Spring 4.2.4.RELEASE.
最佳答案 好吧,这对我来说仍然是个谜.我打赌这是一种奇怪的maven / ide缓存问题,但无论如何这在几次重启后对我有用:
@Lazy(false)
@Component
public class EventListenerImpl {
@EventListener
public void whatever(final ContextRefreshedEvent event) {
event.getSource();
}
}