//获取当前web容器的BeanFactory WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext(); //获取web的上下文信息 ServletContext servletContext = webApplicationContext.getServletContext(); //获取根路径 servletContext.getRealPath("/")