Mongo java driver upgarde from 3.12.1 to 4.2.3 giving class not found execeptions

We have java application based on mongo server 4.2 and component versions are as follows
spring-boot 2.2.5.RELEASE

We had to update spring boot to 2.5.8 hence we made few changes to update dependencies as follow
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

1 Like