最近在搭建完工SpringBoot項目,且配置好logback之後,啓動報錯了,錯誤截圖如下:
文字報錯內容截取關鍵部分如下:
at com.exam.api.boot.Bootstrap.main(Bootstrap.java:44)
Disconnected from the target VM, address: '127.0.0.1:50105', transport: 'socket'
Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@20:84 - no applicable action for [riollingPolicy], current ElementPath is [[configuration][appender][riollingPolicy]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@21:30 - no applicable action for [fileNamePattern], current ElementPath is [[configuration][appender][riollingPolicy][fileNamePattern]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:25 - no applicable action for [maxHistory], current ElementPath is [[configuration][appender][riollingPolicy][maxHistory]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162)
到底是爲何呢?總是提示我 “Logback configuration error detected”,通過這個疑問則考慮瞭如下幾點:
- 】logback版本與SpringBoot衝突問題;
- 】logback.xml配置問題;
- 】maven依賴未成功的問題;
當然主要問題並非是自己想到的三個原因,最關鍵的是logback.xml裏的關鍵字不知到什麼時候多加了一個字母,哎,一言難盡啊。如圖:
這也是部署到linux上導致info.log不顯示的原因。
除此之外,還要注意最重要的一點,就是resources目錄的問題:一般情況下,我們會弄成如下結構:
這樣就完全可以區分出測試環境,線上環境。這時候就要注意目錄問題了,如下是常用的兩種目錄結構:
第一種:resources爲Resources Root:
第一張圖是在pom文件配置的resource路徑
第二張圖是默認設置resources爲Resources Root
第三張install之後配置的目錄環境,在dev下。
第四張圖則是包路徑的引入。
第二種:dev/prod爲Resources Root:
爲了避免自己的大意,平常搭建的過程中,切要細心哈。如果再引入不到的話,我們則可以看看output具體的路徑是映射到了哪裏,如下是我的電腦:
Logback configuration error detected問題而引發的兩個問題就講述到這裏吧,有問題再聯繫。