java.lang.NoSuchMethodError: ‘com.mongodb.MongoClientSettings.getLoggerSettings()’

huangapple go评论68阅读模式
英文:

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-syncmongodb-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

   &lt;dependency&gt;
        &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
        &lt;artifactId&gt;mongodb-driver-sync&lt;/artifactId&gt;
        &lt;version&gt;4.9.1&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
        &lt;artifactId&gt;mongodb-driver-core&lt;/artifactId&gt;
        &lt;version&gt;4.9.1&lt;/version&gt;
    &lt;/dependency&gt;

I see that your build.gradle specifies the same version for both these modules but still:

  • I advise you to run gradle dependencies and confirm that you are indeed using 4.5.1 for both dependencies

  • Both mongo-java-driver and mongodb-driver-async are unmaintained java.lang.NoSuchMethodError: ‘com.mongodb.MongoClientSettings.getLoggerSettings()’

huangapple
  • 本文由 发表于 2023年3月3日 19:47:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75626704.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定