當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Boot 内置Tomcat——IntelliJ IDEA中配置模块目录设为文档根目录(DocumentRoot)解决方案
生活随笔
收集整理的這篇文章主要介紹了
Spring Boot 内置Tomcat——IntelliJ IDEA中配置模块目录设为文档根目录(DocumentRoot)解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
源碼分析
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 archivefile = (file != null) ? file : getWarFileDocumentRoot();// If not a war archive maybe it is an exploded warfile = (file != null) ? file : getExplodedWarFileDocumentRoot();// Or maybe there is a document root in a well-known locationfile = (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 插件啟動
參考文章
springboot 在idea多模塊下 子模塊的web項目用內置tomcat啟動訪問jsp報404
springboot內置Tomcat的getServletContext().getRealPath問題
java中getRealPath("/")和getContextPath()的區別
ServletContext.getRealPath 為 null
總結
以上是生活随笔為你收集整理的Spring Boot 内置Tomcat——IntelliJ IDEA中配置模块目录设为文档根目录(DocumentRoot)解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《服务外包概论》实验报告——版本管理与控
- 下一篇: Spring Boot 内置Tomcat