我正在从 STS 创建一个标准 Spring Boot 1.5.2“Web”项目。如果运行此应用程序,您会创建两个目录 - 普通的“base”目录和“tomcat-docbase”目录
. . . 4096 Mar 29 10:00 tomcat.2743776473678691880.8080
. . . 4096 Mar 29 10:00 tomcat-docbase.76291847886629412.8080
如果我将此项目更改为 WAR 项目,我只会得到“base”目录
. . . 4096 Mar 29 10:06 tomcat.3131223012454570991.8080
使用以下命令可以轻松覆盖默认基目录
server.tomcat.basedir=.
但这对 tomcat-docbase 没有影响。可以通过编程方式覆盖 tomcat-docbase,但看起来像是一种 hack。
有人认为这是一个错误吗?
解决方案:
创建一个文件夹名称为public在您的项目下,与您的 JAR 位于同一文件夹中。
原因:
从springboot代码来看,没有配置docbase文件夹。
但您可以在项目文件夹名称中创建一个公共根文件夹,如下所示public, static or src/main/web应用程序,那么Spring Boot将永远不会再为您创建tmp tomcat-docbase文件夹。
private static final String[] COMMON_DOC_ROOTS = { "src/main/webapp", "public", "static" }
...
public final File getValidDirectory() {
File file = this.directory;
file = (file != null ? file : getWarFileDocumentRoot());
file = (file != null ? file : getExplodedWarFileDocumentRoot());
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;
}
...
private File getCommonDocumentRoot() {
for (String commonDocRoot : COMMON_DOC_ROOTS) {
File root = new File(commonDocRoot);
if (root.exists() && root.isDirectory()) {
return root.getAbsoluteFile();
}
}
return null;
}
Link: 文档根目录.java
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)