1. 直接发请求,可以用下面的方式
ServletContext context = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession().getServletContext();
File nullFile = new File(context.getRealPath(ReportUtil.TPL_FILEPATH_DAILY_REPORT + File.separator + copyTpl.getTplFileNm()));
2. 上面的方式定时器是没法运用的,可以直接用下面的方式
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext context = webApplicationContext.getServletContext();
File nullFile = new File(context.getRealPath(ReportUtil.TPL_FILEPATH_DAILY_REPORT + File.separator + copyTpl.getTplFileNm()));
以上两种方式都是通过 context.getRealPath() 方法来获取项目的路径,然后可以获取项目内固定的文件