spring获取静态资源目录

使用HttpServletRequest

String staticPath= request.getSession().getServletContext().getRealPath("/")+"static/";

使用ContextLoader

WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
String staticPath= servletContext.getRealPath("/") + "static/";

你可能感兴趣的:(Java)