问题描述
我开始了一个全新的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),并建议使用此线程(MongoCommandException: Command failed with error 8000 (AtlasError): 'no SNI name sent,make sure using a MongoDB 3.4+ driver/shell.')
- 我只是为了尝试而更改为JDK 1.8
- 我更改了mongourl样式(在驱动程序3.6及更高版本之间)-并没有帮助
- 在这个问题How to connect Mongodb Atlas to Spring中,我看到有人使用了 non-starter 依赖项进行春季启动。但是,mongo并没有自动检测到这种情况,这不是我想要开发的方式
- 我试图调试mongo驱动程序在做什么,但是...我不知道出了什么问题
这些是我对这项任务的依赖:
// 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"
}
}
编辑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]
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)