tomcat启动完成执行某个方法定时任务(Spring)操作-创新互联
第一步引入接口: ServletContextListener

@RestController
@RequestMapping("/schedule")
public class ScheduleController implements ServletContextListener {
@Autowired
private ScheduleService scheduleService;
@Override
public void contextDestroyed(ServletContextEvent event) {
System.out.println("销毁");
}
@Override
public void contextInitialized(ServletContextEvent event) {
WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext())
.getAutowireCapableBeanFactory().autowireBean(this);
System.out.println("开始执行周期任务");
scheduleService.start(); ;
}
}
本文名称:tomcat启动完成执行某个方法定时任务(Spring)操作-创新互联
标题网址:http://www.jxjierui.cn/article/cdggop.html


咨询
建站咨询
