使用HttpServletRequest
String staticPath= request.getSession().getServletContext().getRealPath("/")+"static/";
使用ContextLoader
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
String staticPath= servletContext.getRealPath("/") + "static/";