英文:
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:<password>@my-cluster.kluqx.gcp.mongodb.net/<db_name>?retryWrites=true&w=majority&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): '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]
...
My tries so far:
- I downloaded a new JDK 11 to be sure I have the proper base (from: https://jdk.java.net/java-se-ri/11) and by suggestion of this thread (https://stackoverflow.com/questions/59112124/mongocommandexception-command-failed-with-error-8000-atlaserror-no-sni-name)
- I changed to JDK 1.8 just to try things
- I changed the mongourl style (between then driver 3.6 and above) - did not help
- I saw in this question https://stackoverflow.com/questions/60398285/how-to-connect-mongodb-atlas-to-spring that someone used the non-starter dependency for spring boot. However this did not automatically detected by mongo stuff which is not how I wanted to develop this
- I tried to debug what the mongo driver is doing but... meh had no idea what is going wrong
These are my dependencies regarding to this task:
// shortened to the relevant parts
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"
}
}
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论