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