Loading

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);
         
    }

 

posted @ 2017-11-11 09:40  stono  阅读(1257)  评论(0编辑  收藏  举报