[JAVA-4438] Mongo java driver upgrade from 3.12.1 to 4.2.3 throws method not found errors Created: 06/Jan/22  Updated: 27/Oct/23  Resolved: 08/Feb/22

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

Type: Question Priority: Major - P3
Reporter: Sanket Chauhan Assignee: Jeffrey Yemin
Resolution: Gone away Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

Hii
We have java application based on mongo server 4.2 and component versions are as follows
spring-boot 2.2.5.RELEASE
spring-data-mongodb2.2.5.RELEASE
mongo-java-driver3.12.1

We had to update spring boot to 2.5.8 hence we made few changes to update dependencies as follow
spring-boot2.5.8
spring-starter-parent2.5.8
spring-data-mongodb 3.2.3
mongodb-driver-core 4.2.3

As we were using newly added import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients; we updated to mongodb-driver-sync 4.2.3

*We resolved all compilation error but on deployment we got errors like methos not found for *getSrvHost() on further debugging we found that old dependency mongo-java-driver 3.3.0 was already present in project

We excluded that and above issue is resolved now no old dependency is present but still we are getting following error without using legacy API approach

java.lang.NoClassDefFoundError: com/mongodb/MongoClient
Caused by: java.lang.NoClassDefFoundError: com/mongodb/MongoClient

We are completely stuck at this point



 Comments   
Comment by PM Bot [ 08/Feb/22 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Jeffrey Yemin [ 10/Jan/22 ]

sanket@yopmail.com no on will be able to move this issue forward without more information about your application, or at least a full stack trace. The only thing we can tell you right now is that your application has ended up with a mix of dependencies between the 3.x and 4.x drivers, and you need to figure out where the 3.x dependencies are coming from and then remove them.  

Without a stack trace, the next best option would be for you to post a full Java project (i.e with Maven pom.xml or equivalent) that demonstrates the problem.

 

Comment by Sanket Chauhan [ 10/Jan/22 ]

There is no stack trace for the same getting single line error only but with further debugging we found that there are few cron job running through our code which are asynchronous.

Mongo java driver 3.12.1 was async driver and we are shifted to mongodb-driver-sync 4.2.3 shifting from async to sync can create such issues?

Is there is any full fleshed document for mongo driver and spring data mongodb upgrade ?

Comment by Mark Paluch [ 07/Jan/22 ]

For the record, Spring Boot 2.5.8 is compatible with Spring Data MongoDB 3.2.x and pulls in the driver version 4.2.3.

Comment by Jeffrey Yemin [ 06/Jan/22 ]

Please paste in the full stack trace for the NoSuchMethodError.  That method was indeed removed in the 4.0 release, so you would need to figure out what is attempting to call it.

Comment by Sanket Chauhan [ 06/Jan/22 ]

On addition of mongodb-driver-legacy 4.2.3 dependency it throws different error java.lang.NoSuchMethodError: com.mongodb.MongoClient.setWriteConcern(Lcom/mongodb/WriteConcern;)V
Caused by: java.lang.NoSuchMethodError: com.mongodb.MongoClient.setWriteConcern(Lcom/mongodb/WriteConcern
If it is related to spring data where can we raise the issue to get help.Thanks in advance!

Comment by Jeffrey Yemin [ 06/Jan/22 ]

Looks like one of your colleagues already reported this in JAVA-4437.  As I commented there, I don't think this is a driver issue.  It may be something with Spring Data or some other dependency of your application.   I suggest adding the dependency on the mongodb-driver-legacy module to work around the issue.

If you do need further help from MongoDB:

  • Our MongoDB support portal, located at support.mongodb.com
  • Our MongoDB community portal, located here
  • If you are an Atlas customer, you can review your support options by clicking Support in the top menu bar of the Atlas UI

 

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