博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Boot 内置Tomcat——IntelliJ IDEA中配置模块目录设为文档根目录(DocumentRoot)解决方案
阅读量:2036 次
发布时间:2019-04-28

本文共 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/

你可能感兴趣的文章
Titan 体系结构概述
查看>>
开始使用Titan
查看>>
DTCC 李文哲:基于图数据库的大数据应用
查看>>
数据库各派系起源、应用场景和选择指南
查看>>
Titan数据库快速入门之决战云巅
查看>>
Titan数据库快速入门之神的光芒
查看>>
WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin
查看>>
一文教你看懂大数据的技术生态圈 Hadoop,hive,spark
查看>>
TinkerPop中的遍历:图的遍历策略
查看>>
The GraphComputer翻译及案例
查看>>
Gremlin简介
查看>>
TinkerPop中的遍历:图的遍历步骤(1/3)
查看>>
TinkerPop中的遍历:图的遍历步骤(2/3)
查看>>
TinkerPop中的遍历:图的遍历步骤(3/3)
查看>>
列出文件和目录
查看>>
RabbitMQ 相关问题汇总
查看>>
精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解!
查看>>
java 给时间增加几个小时方法
查看>>
状态码维护类
查看>>
vmware 和 本地主机共用同一个文件夹
查看>>