Spring Data MongoDB connection to Mongo Atlas throws 'no SNI name sent, make sure using a MongoDB 3.4+ driver/shell' error

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

Spring Data MongoDB connection to Mongo Atlas throws 'no SNI name sent, make sure using a MongoDB 3.4+ driver/shell' error

问题

我开始了一个全新的Kotlin + Spring Boot项目。在这里,我想通过Spring Data MongoDB连接到我的Mongo Atlas集群。

我通过application.properties进行了相当简单的配置(占位符已定义):

spring.data.mongodb.uri=mongodb+srv://backend:<password>@my-cluster.kluqx.gcp.mongodb.net/<db_name>?retryWrites=true&w=majority&authSource=admin

问题:

当应用程序启动时,抛出以下异常:

Caused by: com.mongodb.MongoCommandException: Command failed with error 8000 (AtlasError): 'no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.' on server my-cluster-shard-00-02.kluqx.gcp.mongodb.net:27017. The full response is {"ok": 0, "errmsg": "no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.", "code": 8000, "codeName": "AtlasError"}
at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175) ~[mongodb-driver-core-4.0.5.jar:na]
...

迄今为止的尝试:

  • 我下载了一个新的JDK 11,以确保我有适当的基础(来自:https://jdk.java.net/java-se-ri/11),并根据此线程的建议(https://stackoverflow.com/questions/59112124/mongocommandexception-command-failed-with-error-8000-atlaserror-no-sni-name)。
  • 我切换到JDK 1.8,只是为了尝试一下。
  • 我更改了mongourl的样式(在驱动程序3.6及以上之间) - 没有帮助。
  • 我在这个问题中看到https://stackoverflow.com/questions/60398285/how-to-connect-mongodb-atlas-to-spring,有人使用了Spring Boot的非启动器依赖项。然而,这并没有自动检测到我想要开发的mongo内容,这不是我想要的。
  • 我试图调试Mongo驱动程序正在做什么,但是...哎,不知道出了什么问题。

这是关于这个任务的我的依赖项:

// 缩减为相关部分
plugins {
    id("org.jlleitschuh.gradle.ktlint") version "9.3.0"
    id("org.springframework.boot") version "2.3.3.RELEASE"
    id("io.spring.dependency-management") version "1.0.10.RELEASE"
    kotlin("jvm") version "1.3.72"
    kotlin("plugin.spring") version "1.3.72"
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-actuator")
    implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
    implementation("com.graphql-java:graphql-spring-boot-starter:5.0.2")
    implementation("com.graphql-java:graphql-java-tools:5.2.4")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
    testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo")
    testImplementation("io.projectreactor:reactor-test")
}

java.sourceCompatibility = JavaVersion.VERSION_1_8

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

编辑1:根据Gradle,我的驱动程序如下:

org.mongodb:mongodb-driver-core:4.0.5
org.mongodb:mongodb-driver-sync:4.0.5

你还可以在上面提到的异常中看到,堆栈跟踪与~[mongodb-driver-core-4.0.5.jar:na]相关。

英文:

I started a fresh new Kotlin + Spring Boot project. In here I'd love to connect to my Mongo Atlas cluster via Spring Data MongoDB.

I setup the configuration that is quite simple via application.properties (placeholders were defined):

spring.data.mongodb.uri=mongodb+srv://backend:&lt;password&gt;@my-cluster.kluqx.gcp.mongodb.net/&lt;db_name&gt;?retryWrites=true&amp;w=majority&amp;authSource=admin

The problem:

The following exception is thrown when the app is starting:

Caused by: com.mongodb.MongoCommandException: Command failed with error 8000 (AtlasError): &#39;no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.&#39; on server my-cluster-shard-00-02.kluqx.gcp.mongodb.net:27017. The full response is {&quot;ok&quot;: 0, &quot;errmsg&quot;: &quot;no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.&quot;, &quot;code&quot;: 8000, &quot;codeName&quot;: &quot;AtlasError&quot;}
at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175) ~[mongodb-driver-core-4.0.5.jar:na]
...

My tries so far:

These are my dependencies regarding to this task:

// shortened to the relevant parts
plugins {
    id(&quot;org.jlleitschuh.gradle.ktlint&quot;) version &quot;9.3.0&quot;
    id(&quot;org.springframework.boot&quot;) version &quot;2.3.3.RELEASE&quot;
    id(&quot;io.spring.dependency-management&quot;) version &quot;1.0.10.RELEASE&quot;
    kotlin(&quot;jvm&quot;) version &quot;1.3.72&quot;
    kotlin(&quot;plugin.spring&quot;) version &quot;1.3.72&quot;
}

dependencies {
    implementation(&quot;org.springframework.boot:spring-boot-starter-actuator&quot;)
    implementation(&quot;org.springframework.boot:spring-boot-starter-data-mongodb&quot;)
    implementation(&quot;org.springframework.boot:spring-boot-starter-webflux&quot;)
    implementation(&quot;com.fasterxml.jackson.module:jackson-module-kotlin&quot;)
    implementation(&quot;io.projectreactor.kotlin:reactor-kotlin-extensions&quot;)
    implementation(&quot;org.jetbrains.kotlin:kotlin-reflect&quot;)
    implementation(&quot;org.jetbrains.kotlin:kotlin-stdlib-jdk8&quot;)
    implementation(&quot;org.jetbrains.kotlinx:kotlinx-coroutines-reactor&quot;)
    implementation(&quot;com.graphql-java:graphql-spring-boot-starter:5.0.2&quot;)
    implementation(&quot;com.graphql-java:graphql-java-tools:5.2.4&quot;)
    developmentOnly(&quot;org.springframework.boot:spring-boot-devtools&quot;)
    annotationProcessor(&quot;org.springframework.boot:spring-boot-configuration-processor&quot;)
    testImplementation(&quot;org.springframework.boot:spring-boot-starter-test&quot;) {
        exclude(group = &quot;org.junit.vintage&quot;, module = &quot;junit-vintage-engine&quot;)
    }
    testImplementation(&quot;de.flapdoodle.embed:de.flapdoodle.embed.mongo&quot;)
    testImplementation(&quot;io.projectreactor:reactor-test&quot;)
}

java.sourceCompatibility = JavaVersion.VERSION_1_8

tasks.withType&lt;KotlinCompile&gt; {
    kotlinOptions {
        freeCompilerArgs = listOf(&quot;-Xjsr305=strict&quot;)
        jvmTarget = &quot;1.8&quot;
    }
}

EDIT 1: My drivers are the following according to Gradle:

org.mongodb:mongodb-driver-core:4.0.5
org.mongodb:mongodb-driver-sync:4.0.5

You also can see that in the exception mentioned above where the stacktrace is related to ~[mongodb-driver-core-4.0.5.jar:na]

答案1

得分: 1

问题实际上是JDK。我在每个地方把它改成了14!

  • 项目结构模块和项目
  • Gradle
  • build.gradle 文件
英文:

The problem really was the JDK. I changed it to 14 at every place!

  • Project Structure Modules and Project
  • Gradle
  • build.gradle file

huangapple
  • 本文由 发表于 2020年8月31日 04:20:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63661764.html
匿名

发表评论

匿名网友

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

确定