[JAVA-5083] Driver 4.10.1 class loading issue with Spring Boot Created: 20/Jul/23  Updated: 27/Jul/23  Resolved: 27/Jul/23

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Sher Singh Assignee: Slav Babanin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Hi Team,

We are Facing Error While Upgrading Mongo Atlas DB 6.1 from Java Spring boot Driver 4.10.1 Version. Please Help in Solution.

Error: 

Date of Miliseconds is :- 10 Feb 2022 18:36:16:093 +0530
 
6935 [http-nio-8190-exec-2] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: com/mongodb/internal/diagnostics/logging/Loggers] with root cause
 
java.lang.ClassNotFoundException: com.mongodb.internal.diagnostics.logging.Loggers
 
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
 
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
 
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
 
at com.mongodb.client.internal.MongoClientImpl.<clinit>(MongoClientImpl.java:65)
 
at com.mongodb.client.MongoClients.create(MongoClients.java:108)
 
at com.mongodb.client.MongoClients.create(MongoClients.java:93)
 
at com.mongodb.client.MongoClients.create(MongoClients.java:78)
 
at com.mongodb.client.MongoClients.create(MongoClients.java:61)
 
at com.choice.payprem.MongoDBConnection.getLatestDataFromMongoDB(MongoDBConnection.java:75)
 
at com.choice.payprem.services.PaypremMongoServiceImpl.fetchRecentResumeJourneyData(PaypremMongoServiceImpl.java:413)
 
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.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
 
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
 
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
 
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
 
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
 
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
 
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
 
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
 
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
 
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
 
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
 
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
 
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
 
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
 
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
 
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
 
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
 
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)
 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)
 
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
 
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
 
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
 
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 
at java.lang.Thread.run(Thread.java:748)

POM File:

<dependencies>
 
<dependency>
 
<groupId>org.springframework.boot</groupId>
 
<artifactId>spring-boot-starter-data-rest</artifactId>
 
</dependency>
 
<dependency>
 
<groupId>org.springframework.boot</groupId>
 
<artifactId>spring-boot-starter-jersey</artifactId>
 
</dependency>
 
<dependency>
 
<groupId>org.springframework.boot</groupId>
 
<artifactId>spring-boot-starter-web</artifactId>
 
</dependency>
 
<dependency>
 
<groupId>org.springframework.boot</groupId>
 
<artifactId>spring-boot-starter-tomcat</artifactId>
 
<scope>provided</scope>
 
</dependency>
 
<dependency>
 
<groupId>org.springframework.boot</groupId>
 
<artifactId>spring-boot-starter-test</artifactId>
 
<scope>test</scope>
 
</dependency>
 
<!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync -->
 
<dependency>
 
<groupId>org.mongodb</groupId>
 
<artifactId>mongodb-driver-sync</artifactId>
 
<version>4.10.2</version>
 
</dependency>
 
<dependency>
 
<groupId>org.springframework.boot</groupId>
 
<artifactId>spring-boot-configuration-processor</artifactId>
 
<version>2.0.1.RELEASE</version>
 
</dependency>
 
 
 
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
 
<dependency>
 
<groupId>com.google.code.gson</groupId>
 
<artifactId>gson</artifactId>
 
<version>2.8.9</version>
 
</dependency>
 
<dependency>
 
    <groupId>ch.qos.logback</groupId>
 
    <artifactId>logback-classic</artifactId>
 
    <version>1.2.11</version>
 
  </dependency>
 
 
 
</dependencies>

 

Code to Connect: 

*public* JSONArray getLatestDataFromMongoDB(String database, String collection, Bson filter) {
 
 
 
MongoClient mongoClient = *null*;
 
JSONArray jrr = *new* JSONArray();
 
*try* {
 
mongoClient = MongoClients.{_}create{_}(_uri_);
 
 
 
System.*_out_*.println("Connection Created");
 
MongoCollection<Document> mongoCollection = handleDbConnection(mongoClient, database, collection);
 
 System.*_out_*.println("Connection Created Mongo Collection");
 
 
 
FindIterable<Document> documents = mongoCollection.find(filter);
 
 
 
*if* (documents == *null* || documents.first() == *null*) {
 
System.*_err_*.println("No Data Found");
 
} *else* {
 
*for* (Document document : documents) {
 
 Document jsonDocument = document;
 
JSONObject jb = *new* JSONObject(jsonDocument.toJson());
 
System.*_out_*.println("jb - " + jb);
 
jrr.put(jb);
 
}
 
}
 
} *catch* (Exception e) {
 
System.*_err_*.println("Exception Found" + e.getMessage());
 
e.printStackTrace();
 
*return* {*}null{*};
 
 } *finally* {
 
*if* (mongoClient != *null*) {
 
*try* {
 
mongoClient.close();
 
} *catch* (Exception e) {
 
}
 
}
 
}
 
*return* jrr;
 
}
 
*private* *static* String _uri_ = "mongodb://pa****:0ASf********@pl-1-ap-south-1.wohyz.mongodb.net:1024,pl-1-ap-south-1.wohyz.mongodb.net:1025,pl-1-ap-south-1.wohyz.mongodb.net:1026/?replicaSet=atla*-61gala-s*ard-0&ssl=true&authSource=admin";
 
*private* MongoClient mongoClient = *null*;
 
*import* org.bson.Document;
 
*import* org.bson.conversions.Bson;
 
*import* org.springframework.boot.configurationprocessor.json.JSONArray;
 
*import* org.springframework.boot.configurationprocessor.json.JSONObject;
 
*import* org.springframework.data.rest.webmvc.ResourceNotFoundException;
 
 
 
*import* com.mongodb.client.FindIterable;
 
*import* com.mongodb.client.MongoClient;
 
*import* com.mongodb.client.MongoClients;
 
*import* com.mongodb.client.MongoCollection;
 
*import* com.mongodb.client.MongoDatabase;
 
*import* com.mongodb.client.model.UpdateOptions;
 
*import* com.mongodb.client.result.UpdateResult;

 



 Comments   
Comment by Slav Babanin [ 27/Jul/23 ]

Hi there, thank you for reaching out.

The Loggers class has been moved from com.mongodb.diagnostics.logging to com.mongodb.internal.diagnostics.logging in the 4.8.0 release. It seems like you might have an older version of mongodb-driver-core on your classpath.

Maven follows a "nearest-wins" strategy for resolving dependencies, choosing the closest version to your project in the dependency tree when multiple versions exist. If dependency versions are retrieved from the dependency management section or if spring-boot-starter-parent is used (which uses spring-boot-dependencies as a parent), it may cause the lower mongodb-driver-core version to be used.

As this sounds like a support issue, I wanted to give you some resources to get this question answered more quickly:

  • Our MongoDB support portal, located at support.mongodb.com
  • Our MongoDB community portal, located here
  • If you are an Atlas customer, you can also: Click the in-app chat icon in the lower right corner to chat with a MongoDB Support representative OR Click Support in the left-hand navigation to view Developer Resources.

Just in case you have already opened a support case and are not receiving sufficient help, please let me know and I can facilitate escalating your issue.

Thank you!

Comment by PM Bot [ 20/Jul/23 ]

Hi sher.singh@canarahsbclife.in, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Thu Feb 08 09:03:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.