Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2864

Getting java.lang.ClassNotFoundException: com.mongodb.MongoClient while using mongodb-driver-sync(4.0.4) instead of mongo-java-driver

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.9.1, 2.13.3
    • 2.9.1, 2.13.3
    • Appenders, MongoDB
    • None
    • Development.

    Description

      I'm getting the below error while using the log4j2 with mongo-driver-sync instead of mongo-java-driver. Although it's working fine with mongo-java-driver. I'm trying to upgrade my mongo db with 4.2 and i'm using mongo java driver 4.0 that is mongo-driver-sync. So i have removed all the previous dependencies including mongo-java-driver. But Logging started giving me the below Errors. 
      Error:

      java.lang.ClassNotFoundException: com.mongodb.MongoClient
          at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
          at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
          at org.apache.logging.log4j.nosql.appender.mongodb.MongoDbProvider$Builder.build(MongoDbProvider.java:298)
          at org.apache.logging.log4j.nosql.appender.mongodb.MongoDbProvider$Builder.build(MongoDbProvider.java:132)
          at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
          at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:942)
          at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:882)
          at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:874)
          at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:874)
          at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:498)
          at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:227)
          at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:239)
          at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:530)
          at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:603)
          at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
          at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:226)
          at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
          at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
          at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
          at org.apache.commons.logging.LogFactory$Log4jLog.<clinit>(LogFactory.java:199)
          at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
          at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
          at org.springframework.web.servlet.DispatcherServlet.<clinit>(DispatcherServlet.java:274)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
          at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
          at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1042)
          at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:983)
          at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4871)
          at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5180)
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
          at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
          at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
          at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
          at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
          at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
          at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
          at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
          at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
          at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
          at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
          at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
          at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
          at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343)
          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:474)
      
      

      Log4j2.xml:

      <NoSql name="MongoAppender" bufferSize="10"> <!--Recommended bufferSize configuration to reduce frequent write operations. -->
                  <MongoDb databaseName="mydb"
                      collectionName="logs" server="localhost" port="27017"/>
                  <ThresholdFilter level="WARN" onMatch="ACCEPT"
                      onMismatch="DENY" />
              </NoSql>
      

      Dependencies :

      <dependency>
              <groupId>org.mongodb</groupId>
              <artifactId>mongodb-driver-sync</artifactId>
              <version>4.0.4</version>
          </dependency>
      
       <dependency>
              <groupId>org.apache.logging.log4j</groupId>
              <artifactId>log4j-nosql</artifactId>
              <version>2.9.1</version>
          </dependency>
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            Tanuj92 Tanuj
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: