Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

500
Views
Mongo java driver upgrade from 3.12.1 to 4.2.3 throwing method/class not found execptions on deployment

I 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

I updated spring boot to 2.5.8 hence 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

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>3.2.3</version>
</dependency>

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-core</artifactId>
    <version>4.2.3</version>
</dependency>

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-sync</artifactId>
    <version>4.2.3</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.8</version>
</dependency>

As I used newly added

**import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;**

i.e mordern API using mongo-java driver 3.12.1 I updated to mongodb-driver-sync 4.2.3

I resolved all compilation errors but on deployment got errors like method not found for getSrvHost() on further debugging found that old dependency of mongo-java-driver 3.3.0 was already present in project

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

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

Completely stuck at this point in driver and spring upgrade process, without using com.mongodb.MongoClient in entire project it is throwing error on deployment.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It's recommended use spring-boot-starter-parent as <parent> to use compatible versions.

Just add the spring-boot-starter-data-mongodb dependency and it has all the necessary MongoDB drivers.
Remove from pom.xml: spring-data-mongodb, mongodb-driver-core, spring-starter-parent

Note: Always use the last version, since 2.5.8 has 3 vulnerabilities

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.2</version>
    <relativePath/>
</parent>

...
<dependencies>
    ...

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>

</dependencies>

Dependency Hierarchy

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!