I’m working on springboot mvc gradle project. I upgraded some versions due to which now when I’m running the api to connect and save data in my mongodb. It gives me this error –
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.mongodb.client.MongoCollection.insertMany(Ljava/util/List;)Lcom/mongodb/client/result/InsertManyResult;] with root cause
java.lang.NoSuchMethodError: com.mongodb.client.MongoCollection.insertMany(Ljava/util/List;)Lcom/mongodb/client/result/InsertManyResult;
at org.springframework.data.mongodb.core.MongoTemplate.lambda$insertDocumentList$17(MongoTemplate.java:1491) ~[spring-data-mongodb-3.3.1.jar:3.3.1]
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:555) ~[spring-data-mongodb-3.3.1.jar:3.3.1]
I tried to resolve some version conflict. But the thing is I don’t see any mongodb version conflict. Can someone help me to explain what I wrong and how it can be resolved.
org.springframework.boot:spring-boot-starter-data-mongodb:2.6.3
| +--- org.springframework.boot:spring-boot-starter:2.6.3 (*)
| +--- org.mongodb:mongodb-driver-sync:4.4.1
| | +--- org.mongodb:bson:4.4.1
| | \--- org.mongodb:mongodb-driver-core:4.4.1
| | \--- org.mongodb:bson:4.4.1
| \--- org.springframework.data:spring-data-mongodb:3.3.1
| +--- org.springframework:spring-tx:5.3.15 (*)
| +--- org.springframework:spring-context:5.3.15 (*)
| +--- org.springframework:spring-beans:5.3.15 (*)
| +--- org.springframework:spring-core:5.3.15 (*)
| +--- org.springframework:spring-expression:5.3.15 (*)
| +--- org.springframework.data:spring-data-commons:2.6.1
| | +--- org.springframework:spring-core:5.3.15 (*)
| | +--- org.springframework:spring-beans:5.3.15 (*)
| | \--- org.slf4j:slf4j-api:1.7.32 -> 1.7.33
| +--- org.mongodb:mongodb-driver-core:4.4.1 (*)
build.gradle –
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.3")
}
}
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
}
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation 'org.apache.avro:avro:1.9.1'
implementation 'org.json:json:20171018'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation 'com.amazonaws:aws-java-sdk-s3'
implementation "org.apache.kafka:kafka-clients:3.1.0"
implementation(group: 'commons-io', name: 'commons-io', version: '2.11.0')
implementation group: 'org.springframework.kafka', name: 'spring-kafka', version: '2.8.2'
testImplementation "junit:junit"
implementation 'com.github.javadev:underscore:1.47'
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
implementation 'org.mongodb:mongo-java-driver:3.12.10'
implementation 'com.h2database:h2:1.4.200'
implementation 'com.splunk:splunk:1.6.5.0'
implementation 'com.google.guava:guava:13.0.1'
implementation("org.springframework.boot:spring-boot-starter-batch")
implementation 'com.google.code.gson:gson:2.8.6'
implementation group: 'com.opencsv', name: 'opencsv', version: '4.6'
implementation 'org.springframework.boot:spring-boot-starter:2.6.3'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.6.3'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.batch:spring-batch-test'
}