import org.springframework.web.context.ContextLoader; import javax.servlet.ServletContext; /** * Created by Gong_Yi on 2018/1/26. */ public class G { String webRootUrl = "/"; ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext(); String webRootPath = servletContext.getRealPath(webRootUrl); }