ClassNotFoundException:org.apache.commons.logging.LogFactory

ClassNotFoundException:org.apache.commons.logging.LogFactory

Webアプリケーションを起動しますが、次のエラーメッセージが表示されます。

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

1. 通常の場合

1.1 Obviously, the Apache Commons logging is missing – commons-logging-xxx.jar. 修正するには、Maven中央リポジトリから入手してください。

pom.xml

   
      commons-logging
      commons-logging
      1.2
   

2. スプリングケース

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

pom.xml

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

上記の宣言により、このclassNotFoundException: 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}