Я использую MongoBee для миграции, получаю исключение на mongoTemplate.insertAll (аэропорты);
@ChangeLog(order = "001")
public class DbChangeLog001 {
@ChangeSet(order = "001", id = "seedProduct", author = "San")
public void seedProduct(MongoTemplate mongoTemplate) {
Product rome = new Product("Name" , "45.9","Desc");
Product paris = new Product("Name" , "45","Desc");
Product copenhagen = new Product("Name" , "45","Desc");
List<Product> airports = Arrays.asList(rome, paris, copenhagen);
mongoTemplate.insertAll(airports);
}
}
Проблема вызвана зависимостями, я знаю, но не знаю как решить проблему
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'org.springdoc:springdoc-openapi-ui:1.4.3'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
compile "org.mongodb:mongo-java-driver:3.12.6"
compile 'org.javassist:javassist:3.18.2-GA' // workaround for ${javassist.version} placeholder issue*
compile('com.github.mongobee:mongobee:0.13') {
exclude group: 'org.mongodb'
}
}
Из документа Mongobee есть известная проблема
mongobee depends on mongo-java-driver. If your application has mongo-java-driver dependency too, there could be a library conflicts in some cases.
Они показали способ обхода как
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.github.mongobee</groupId>
<artifactId>mongobee</artifactId>
<version>0.9</version>
<exclusions>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
У меня есть следуя той же инструкции, удалили зависимость mongodb от Mongobee, но вызвали новую ошибку
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.data.mongodb.core.MongoTemplate.lambda$insertDocumentList$16(MongoTemplate.java:1468)
The following method did not exist:
'com.mongodb.client.result.InsertManyResult com.mongodb.client.MongoCollection.insertMany(java.util.List)'
The method's class, com.mongodb.client.MongoCollection, is available from the following locations:
jar:file:/Users/macbook/.gradle/caches/modules-2/files-2.1/org.mongodb/mongo-java-driver/3.12.6/357010b0cdc0e6b2e1fc62e589be4a2c1e0050d1/mongo-java-driver-3.12.6.jar!/com/mongodb/client/MongoCollection.class
jar:file:/Users/macbook/.gradle/caches/modules-2/files-2.1/org.mongodb/mongodb-driver-sync/4.0.4/3f1538a82a5a8ba8d41f22dd61bb17b30f1a9407/mongodb-driver-sync-4.0.4.jar!/com/mongodb/client/MongoCollection.class
The class hierarchy was loaded from the following locations:
com.mongodb.client.MongoCollection: file:/Users/macbook/.gradle/caches/modules-2/files-2.1/org.mongodb/mongo-java-driver/3.12.6/357010b0cdc0e6b2e1fc62e589be4a2c1e0050d1/mongo-java-driver-3.12.6.jar