只要在Web应用程序上下文中声明了bean,就可以获取
ServletContext(使用
ServletContextAware或通过自动装配)的实例。
然后你就可以在webapp目录直接访问文件(
getResourceAsStream(),
getRealPath()),或使用
ServletContextResource。
由momo编辑:
@AutowiredServletContext servletContext;... myMethod() { File rootDir = new File( servletContext.getRealPath("/WEB-INF/myDIR/") );}


