本文共 1536 字,大约阅读时间需要 5 分钟。
org.springframework.boot.web.servlet.server.DocumentRoot
/** * Returns the absolute document root when it points to a valid directory, logging a * warning and returning {@code null} otherwise. * @return the valid document root */ final File getValidDirectory() { File file = this.directory; // If document root not explicitly set see if we are running from a war archive file = (file != null) ? file : getWarFileDocumentRoot(); // If not a war archive maybe it is an exploded war file = (file != null) ? file : getExplodedWarFileDocumentRoot(); // Or maybe there is a document root in a well-known location file = (file != null) ? file : getCommonDocumentRoot(); if (file == null && this.logger.isDebugEnabled()) { logNoDocumentRoots(); } else if (this.logger.isDebugEnabled()) { this.logger.debug("Document root: " + file); } return file; }
发现有三种取路径方式:
war包 getWarFileDocumentRoot
导出包 getExplodedWarFileDocumentRoot
文档 getCommonDocumentRoot
内置tomcat启动应该属于第三种。
private static final String[] COMMON_DOC_ROOTS = { "src/main/webapp", "public","static" };
private File getCommonDocumentRoot() { for (String commonDocRoot : COMMON_DOC_ROOTS) { File root = new File(commonDocRoot); if (root.exists() && root.isDirectory()) { return root.getAbsoluteFile(); } } return null; }
百度得知 取的是
System.getProperty("user.dir")
相当于
File root = new File(System.getProperty("user.dir")+"src/main/webapp");
输出 System.getProperty("user.dir") 发现是项目层目录,而不是模块层目录
方法一:启动项增加配置参数
方法二:Spring Boot 插件启动
转载地址:http://ciwof.baihongyu.com/