/ tmp / tomcat-docbase总是使用Spring Boot JAR创建(但不是WAR) [英] /tmp/tomcat-docbase is always created with a Spring Boot JAR (but not a WAR)
问题描述
从STS我正在创建一个标准的Spring Boot 1.5.2'Web'项目。如果运行此应用程序,则会创建两个目录 - 正常的base目录和tomcat-docbase目录
From STS I'm creating a standard Spring Boot 1.5.2 'Web' project. If you run this application you get two directories created - the normal 'base' directory and a 'tomcat-docbase' directory
. . . 4096 Mar 29 10:00 tomcat.2743776473678691880.8080
. . . 4096 Mar 29 10:00 tomcat-docbase.76291847886629412.8080
如果我将此项目更改为WAR项目我只获取'base'目录
If I change this project to a WAR project I get only the 'base' directory
. . . 4096 Mar 29 10:06 tomcat.3131223012454570991.8080
使用
It's easy to override the default base directory using
server.tomcat.basedir=.
但是这对tomcat-docbase没有影响。可以通过编程方式覆盖tomcat-docbase,但看起来像是一个黑客。
however this has no effect on tomcat-docbase. It is possible to override tomcat-docbase programmatically but seems like a hack.
有人认为这是一个错误吗?
Does anyone think this is a bug?
谢谢
推荐答案
解决方案:
在您的项目下创建一个文件夹名称 public ,与您的文件夹在同一文件夹中JAR。
Solution: create a folder name as public under your project, in the same folder with your JAR.
原因:来自springboot代码的
,没有docbase文件夹的配置。
,但您可以在项目文件夹名称中创建一个公共根文件夹,如 public , static 或 src / main / webapp ,然后springboot永远不会再为你创建临时tomcat-docbase文件夹。
Reason: from the springboot code, there is no configuration for docbase folder. but you can create a common root folder in you project folder name as public, static or src/main/webapp, then the springboot will never create temp tomcat-docbase folder for you again.
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;
}
这篇关于/ tmp / tomcat-docbase总是使用Spring Boot JAR创建(但不是WAR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!