英文:
java.lang.NoSuchMethodError: 'com.mongodb.LoggerSettings com.mongodb.MongoClientSettings.getLoggerSettings()'
问题
运行一个JAR文件时出现错误
java.lang.NoSuchMethodError: 'com.mongodb.LoggerSettings com.mongodb.MongoClientSettings.getLoggerSettings()'
at com.mongodb.reactivestreams.client.MongoClients.createCluster(MongoClients.java:150)
at com.mongodb.reactivestreams.client.MongoClients.createMongoClient(MongoClients.java:139)
at com.mongodb.reactivestreams.client.MongoClients.createWithAsynchronousSocketChannel(MongoClients.java:175)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:116)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:87)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:72)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:62)
at com.mongo.clients.MongoDBReactiveApp.dbActions(MongoDBReactiveApp.java:32)
at com.mongo.clients.MongoDBReactiveApp.start(MongoDBReactiveApp.java:18)
at com.mongo.MongoApplication.start(MongoApplication.java:49)
at com.mongo.MongoApplication.main(MongoApplication.java:25)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
**build.gradle文件包含以下设置**。
dependencies {
implementation group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.10'
implementation group: 'org.mongodb', name: 'mongodb-driver-async', version: '3.12.10'
implementation group: 'org.mongodb', name: 'mongodb-driver-reactivestreams', version: '4.5.1'
implementation group: 'args4j', name: 'args4j', version: '2.33'
// implementation group: 'org.mongodb', name: 'mongodb-driver-core', version: '4.3.4'
implementation group: 'org.mongodb', name: 'bson', version: '4.5.1'
implementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: '4.5.1'
implementation group: 'org.mongodb', name: 'mongodb-driver-core', version: '4.5.1'
implementation 'commons-logging:commons-logging:1.1.3'
}
我尝试了多个版本的mongo-java-driver,但都没有起作用。还使用了构建器类。
英文:
i am running a jar file and it is throwing error
java.lang.NoSuchMethodError: 'com.mongodb.LoggerSettings com.mongodb.MongoClientSettings.getLoggerSettings()'
at com.mongodb.reactivestreams.client.MongoClients.createCluster(MongoClients.java:150)
at com.mongodb.reactivestreams.client.MongoClients.createMongoClient(MongoClients.java:139)
at com.mongodb.reactivestreams.client.MongoClients.createWithAsynchronousSocketChannel(MongoClients.java:175)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:116)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:87)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:72)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:62)
at com.mongo.clients.MongoDBReactiveApp.dbActions(MongoDBReactiveApp.java:32)
at com.mongo.clients.MongoDBReactiveApp.start(MongoDBReactiveApp.java:18)
at com.mongo.MongoApplication.start(MongoApplication.java:49)
at com.mongo.MongoApplication.main(MongoApplication.java:25)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
build.gradle file have following setting.
dependencies {
implementation group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.10'
implementation group: 'org.mongodb', name: 'mongodb-driver-async', version: '3.12.10'
implementation group: 'org.mongodb', name: 'mongodb-driver-reactivestreams', version: '4.5.1'
implementation group: 'args4j', name: 'args4j', version: '2.33'
// implementation group: 'org.mongodb', name: 'mongodb-driver-core', version: '4.3.4'
implementation group: 'org.mongodb', name: 'bson', version: '4.5.1'
implementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: '4.5.1'
implementation group: 'org.mongodb', name: 'mongodb-driver-core', version: '4.5.1'
implementation 'commons-logging:commons-logging:1.1.3'
}
i tried with multiple version of mongo-java-driver but it didn't worked.
also use builder class
答案1
得分: 1
在我的情况下,我遇到了这个确切的错误,因为我在mongodb-driver-sync
和mongodb-driver-core
使用了两个不同的版本。
通过在项目根目录中运行mvn dependency:tree
(在gradle中应该是gradle dependencies
)来查找这个问题,并看到其中一个设置为4.8.2
,另一个为4.9.1
。
我通过在我的pom.xml中明确声明这两个依赖项的版本为4.9.1来解决了这个问题。
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.9.1</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>4.9.1</version>
</dependency>
我注意到你的build.gradle为这两个模块指定了相同的版本,但仍然:
英文:
In my case I got this exact error because I was using two different versions for mongodb-driver-sync
and mongodb-driver-core
.
I was able to spot this by running mvn dependency:tree
(in gradle it should be gradle dependencies
) in the project root and see that one of them was set to 4.8.2
and the other 4.9.1
.
I fixed it by declaring these two dependencies explicitly with version 4.9.1 in my pom.xml
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.9.1</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>4.9.1</version>
</dependency>
I see that your build.gradle specifies the same version for both these modules but still:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论