Dav*_*lia 4 java spring tomcat spring-boot
从STS,我正在创建一个标准的Spring Boot 1.5.2'Web'项目。如果运行此应用程序,则会创建两个目录-普通的“基本”目录和“ tomcat-docbase”目录
. . . 4096 Mar 29 10:00 tomcat.2743776473678691880.8080
. . . 4096 Mar 29 10:00 tomcat-docbase.76291847886629412.8080
Run Code Online (Sandbox Code Playgroud)
如果我将此项目更改为WAR项目,则仅获得“基本”目录
. . . 4096 Mar 29 10:06 tomcat.3131223012454570991.8080
Run Code Online (Sandbox Code Playgroud)
使用以下方法覆盖默认的基本目录很容易
server.tomcat.basedir=.
Run Code Online (Sandbox Code Playgroud)
但这对tomcat-docbase没有影响。可以通过编程方式覆盖tomcat-docbase,但看起来像是黑客。
有人认为这是一个错误吗?
谢谢
解决方案:创建一个文件夹的名称作为公共项目下,使用您的JAR相同的文件夹。
原因:从springboot代码来看,docbase文件夹没有配置。但是您可以在项目文件夹名称中创建公用根文件夹,名称为public,static或src / main / webapp,然后springboot永远不会再为您创建temp 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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4211 次 |
| 最近记录: |