springboot-监听器

如添加一个监听项目启动的监听器:

1.application添加注解

@ServletComponentScan

2.写监听器
@WebListener
public class QuartzJobListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent arg0) {

// QuartzManager类是一个@service,通过类名获取bean
        QuartzManager quartzManager = WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext()).getBean(QuartzManager.class);
        System.out.println("QuartzJobListener 启动了");
    }
    public void contextDestroyed(ServletContextEvent arg0) {
    }

}

猜你喜欢

转载自blog.csdn.net/qq_41665356/article/details/89182807