1. 程式人生 > >【log4j】log4j找不到配置檔案

【log4j】log4j找不到配置檔案

log4j報錯:ERROR StatusLogger No log4j2 configuration file found. Using default configuration

但是classpath分明存在配置檔案(maven編譯生成的target/classes/目錄下有log4j2.yml)

把log4j更新到2.10,執行時設定系統環境變數:-Dlog4j.debug=true,檢視log4j內部日誌記錄,發現是處理yaml檔案的依賴沒有(可以檢視org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory的程式碼)

就很鬱悶,那你報什麼配置檔案找不到?

最後新增依賴:

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.4</version>
</dependency>


<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>


<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.4</version>
</dependency>


<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>

後不再報這個錯誤