public class FirstListen implements ServletContextListener{ @Override public void contextDestroyed(ServletContextEvent sce) { } @Override public void contextInitialized(ServletContextEvent sce) { } } @SpringBootApplication public class Demo1 { public static void main(String[] args) { SpringApplication.run(Demo1.class, args); } /** * 注册Listener * @return */ @Bean public ServletListenerRegistrationBean<FirstListen> get2() { ServletListenerRegistrationBean<FirstListen> ben = new ServletListenerRegistrationBean<>(new FirstListen()); return ben; }