【原】Could not initialize class org.apache.log4j.Log4jLoggerFactory
阿新 • • 發佈:2018-08-08
考題 ted log clas .com alt 代碼 light nbsp
- 現象:正常運行的項目,從Jenkins遷到容器雲上不能正常啟動,報錯誤如下:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4jLoggerFactory
缺Log4j不可能,絕對不可能,同個版本的代碼剛剛還在Jenkins上起來的。怎麽辦,仔細讀下日誌,發現有如下提示:
很明顯了,看來是log4j-over-slf4j.jar 和 slf4j-log4j12.jar 不能在同一個class path。
- 解決:
- 利用maven找jar包沖突,執行依賴樹命令,用 omitted for conflict with 檢索。
mvn -X compile dependency:tree -Dverbose >a.log
2. 排除依賴,即可。
<dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-cas</artifactId> <version>${spring.security.version}</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>jul-to-slf4j</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions> </dependency>
- 思考:
- 為什麽之前Jenkins上能正常啟動?猜測是tomcat8和tomcat7的區別吧。這是我這邊看到的差別。最近很忙,留個思考題以後抽時間確認下。TODO
- 遇到問題看日誌信息還是非常重要!
【原】Could not initialize class org.apache.log4j.Log4jLoggerFactory