日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Boot 内置Tomcat——IntelliJ IDEA中配置模块目录设为文档根目录(DocumentRoot)解决方案

發布時間:2024/10/5 javascript 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。