gpt4 book ai didi

将 Spring Boot Starter Web 依赖项与 Mongo Driver 3.11.0 一起使用时出现 java.lang.NoSuchMethodError

转载 作者:行者123 更新时间:2023-12-01 19:35:18 25 4
gpt4 key购买 nike

将 Spring Boot Starter Web 依赖项与最新的 MongoDB 驱动程序 3.11.0 结合使用会出现以下错误。当我切换到旧版本的 Mongo Driver(如 3.8.2)时,效果很好。有任何想法吗?我应该排除 Mongo 依赖吗?

如果我删除 spring boot 依赖项,Mongo 连接工作正常。

06:39:09.046 [main] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[host1:27017, host2:27017, host3:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
06:39:09.048 [main] INFO org.mongodb.driver.cluster - Adding discovered server host1:27017 to client view of cluster
06:39:09.079 [main] INFO org.mongodb.driver.cluster - Adding discovered server host2:27017 to client view of cluster
06:39:09.080 [main] INFO org.mongodb.driver.cluster - Adding discovered server host3:27017 to client view of cluster
06:39:09.083 [main] DEBUG org.mongodb.driver.cluster - Updating cluster description to {type=UNKNOWN, servers=[{address=host3:27017, type=UNKNOWN, state=CONNECTING}, {address=host1:27017, type=UNKNOWN, state=CONNECTING}, {address=host2:27017, type=UNKNOWN, state=CONNECTING}]
Exception in thread "main" java.lang.NoSuchMethodError: com.mongodb.MongoClientSettings.getAutoEncryptionSettings()Lcom/mongodb/AutoEncryptionSettings;
at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:67)
at com.mongodb.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:61)
at com.mongodb.client.MongoClients.create(MongoClients.java:114)
at com.mongodb.client.MongoClients.create(MongoClients.java:99)
at com.mongodb.client.MongoClients.create(MongoClients.java:83)
at com.mongodb.client.MongoClients.create(MongoClients.java:61)
at com.mongo.demo.MongoDemo.main(MongoDemo.java:98)

下面的pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>mongo-test</groupId>
<artifactId>mongo-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mongo-test</name>
<description>Mongo Test</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>

</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

最佳答案

你能尝试一下这个依赖吗

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

而不是

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

关于将 Spring Boot Starter Web 依赖项与 Mongo Driver 3.11.0 一起使用时出现 java.lang.NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57975730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com