springmvc中用注解写了一个定时器,想在其中获取web上下文servletContext,或者简单一点的获得当前项目的绝对路径怎么弄???
网上有人说这样:
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
但是我获取的webApplicationContext是空的,会报异常。