我有以下应用程序启动器:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication();
springApplication.setListeners(Collections.singleton(new MyListenrer()));
springApplication.run(MyApplication.class, args)
}
public static class MyListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent>{
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent applicationEnvironmentPreparedEvent) {
System.out.println("invoked");
}
}
}
但是我的听众没有调用。
如何解决?
它有效:
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication();
springApplication.setListeners(Collections.singleton(new MyListener()));
springApplication.setSources(MyApplication.class);
springApplication.run(args) ///!!!!!
}