spring定时器中如何获取servletcontext
spring定时器中如何获取servletcontext
学习了:https://zhidao.baidu.com/question/406212574.html
@Scheduled(cron = "0 0 */3 * * ?") // 3小时处理一次 public void updateData(){ System.out.println("*********************************schedule task"); WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext(); ServletContext context = webApplicationContext.getServletContext(); List<Tbl> tblList = tblMapper.getAll(); context.setAttribute("tbl", tblList); }