我有以下应用程序入门:

@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) ///!!!!!
}

关于java - 未收到ApplicationEnvironmentPreparedEvent,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54651340/

10-10 13:09