spring定时器中如何获取servletcontext
Posted stono
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); }
以上是关于spring定时器中如何获取servletcontext的主要内容,如果未能解决你的问题,请参考以下文章