ClassNotFoundException: org.apache.commons.logging.LogFactory

ClassNotFoundException: org.apache.commons.logging.LogFactory

Beim Starten einer Webanwendung werden jedoch die folgenden Fehlermeldungen angezeigt:

...
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
...

1. Normalfall

1.1 Obviously, the Apache Commons logging is missing – commons-logging-xxx.jar. Um das Problem zu beheben, beziehen Sie es aus dem zentralen Repository von Maven.

pom.xml

   
      commons-logging
      commons-logging
      1.2
   

2. Frühling Fall

2.1 For Spring application, developers always excluded the commons-logging, but forget to include another logging framework. Beispielsweise

pom.xml

   
      org.springframework
      spring-webmvc
      ${spring.version}
      
          
          commons-logging
          commons-logging
          
      
   

Die obige Deklaration verursacht auch dieseclassNotFoundException: 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}