ClassNotFoundException: org.apache.commons.logging.LogFactory
Démarrage d'une application Web, mais frappe les messages d'erreur suivants:
... Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory ...
1. Cas normal
1.1 Obviously, the Apache Commons logging is missing – commons-logging-xxx.jar
. Pour le corriger, récupérez-le dans le référentiel central Maven.
pom.xml
commons-logging commons-logging 1.2
2. Spring Case
2.1 For Spring application, developers always excluded the commons-logging
, but forget to include another logging framework. Par exemple
pom.xml
org.springframework spring-webmvc ${spring.version} commons-logging commons-logging
La déclaration ci-dessus provoquera également cesclassNotFoundException: org.apache.commons.logging.LogFactory
.
2.2 To fix it, declares another logging framework, often, this is SLF4j and redirect the Spring’s logging via a bridge.
pom.xml
org.springframework spring-webmvc ${spring.version} commons-logging commons-logging org.slf4j jcl-over-slf4j ${jcl.slf4j.version} ch.qos.logback logback-classic ${logback.version}