ClassNotFoundException:org.apache.commons.logging.LogFactory
程序员文章站
2022-07-15 13:10:46
...
正在启动Web应用程序,但出现以下错误消息:
... Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory ...
1.正常情况
1.1显然,缺少Apache Commons日志commons-logging-xxx.jar
。 要修复它,请从Maven*存储库中获取它。
pom.xml
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
2.弹簧套
2.1对于Spring应用程序,开发人员总是排除commons-logging
,但是忘记包括另一个日志记录框架。 例如
pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
上面的声明将导致此类classNotFoundException: org.apache.commons.logging.LogFactory
也。
2.2要修复该问题,请声明另一个日志框架,通常是SLF4j,并通过网桥重定向Spring的日志。
pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- bridge jck to slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${jcl.slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
参考文献
From: https://mkyong.com/java/javalangnoclassdeffounderror-orgapachecommonslogginglogfactory/
推荐阅读
-
myeclipse编程提示ClassNotFoundException错误怎么办?
-
Spring Boot 2.3.6 与 Spring kafka 集成 出错(ClassNotFoundException: org.springframework.kafka.core.Microm
-
JAVA forname classnotfoundexception 错误
-
使用IDEA启动项目遇见ClassNotFoundException的解决方案
-
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener
-
Android <java.lang.ClassNotFoundException:Didn‘t find class ‘XXX‘ on path:DexPathList> 解决
-
idea启动项目报错Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
-
ClassNotFoundException和 NoClassDefFoundError的区别
-
java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory 异常错误
-
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory