我的EventListener
注解没有接收到任何Spring事件。这是我的代码:
@Component
public class ProxyConfig {
public ProxyConfig() {
System.out.println("I can see this in the console");
}
@EventListener
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
System.out.println("WON'T WORK :-("); // FIXME
}
@EventListener
public void test(ApplicationStartedEvent event) {
System.out.println("WON'T WORK :-("); // FIXME
}
}
这是我的 Application
类:
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(MyApp.class, args);
}
}
根据https://spring.io/blog/2015/02/11/better-application-events-in-spring-framework-4-2和https://solidsoft.wordpress.com/2015/09/29/annotation-driven-event-listeners-in-spring-4-2/,它应该可以工作,但仍然无法打印我的"WON'T WORK :-("字符串 :(
有什么想法吗?
谢谢!
Application
和ProxyConfig
在哪些包中? - Andy WilkinsonApplication
位于包com.mycompany.app
中。而ProxyConfig
则在子包com.mycompany.app.configuration.impl
中。 - user6479676META-INF/spring.factories
文件(参见 http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-spring-application.html#boot-features-application-events-and-listeners),可以在没有注释的情况下运行,但是有注释就不行了... :( - user6479676