java - MongoCommandException : Command failed with error 8000 (AtlasError): 'no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.'

标签 java mongodb connection

我正在使用 Java 11(Maven 项目)作为 mongodb 免费层集群(版本 4.0.13)。我正在尝试通过连接字符串(对于 3.6 驱动程序或更高版本)进行连接,例如:

mongodb+srv://user:pass@cluster0-ox90k.mongodb.net/test?retryWrites=true&w=majority

并通过连接字符串以相同的方式(对于 3.4 驱动程序或更高版本):

mongodb://user:pass@cluster0-shard-00-00-ox90k.mongodb.net:27017,cluster0-shard-00-01-ox90k.mongodb.net:27017,cluster0-shard-00-02-ox90k.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority

我已经测试了java驱动程序的不同依赖项,例如:mongodb-driver-sync(版本3.11.0)、mongodb-driver-sync(版本3.10.0)、mongodb-driver-sync(版本3.8) .0)。

Maven 依赖关系如下所示:

 <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongodb-driver-sync</artifactId>
      <version>3.11.0</version>
 </dependency>

我还尝试通过连接字符串使用mongo-java-driver用于3.6或更高版本的驱动程序/3.4或更高版本以及诸如3.11.0、3.10之类的版本。 0、3.8.0、3.7.0。

Maven 依赖关系如下所示:

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>3.11.0</version>
</dependency>

我总是遇到同样的问题:

Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 8000: 'no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.' on server cluster0-shard-00-01-ox90k.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.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:164)
    at com.mongodb.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:286)
    at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:247)
    at com.mongodb.connection.CommandHelper.sendAndReceive(CommandHelper.java:84)
    at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:34)
    at com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:91)
    at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:51)

我当前的 POM 是:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test_project</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <!-- jsoup HTML parser library @ https://jsoup.org/ -->
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.3</version>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.11.0</version>
        </dependency>   
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>    
                </configuration>
                <executions>
                    <execution>
                        <id>assemble-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>    
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>project.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

任何如何解决该问题的想法将不胜感激。

最佳答案

我在使用 adoptopenjdk/openjdk11-openj9:jdk-11.0.1.13-alpine-slim 中的 Docker 镜像时遇到了同样的问题。由于我已升级到 adoptopenjdk/openjdk11-openj9:jdk-11.0.5.10-alpine-slim,因此我与 MongoDB 的连接正常。

关于java - MongoCommandException : Command failed with error 8000 (AtlasError): 'no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59112124/

相关文章:

java - 碧 Jade 报告 : multi line text field

java - 即使我声明了 Android 权限也不起作用

java - spring中如何实现动态更新sql

linux - 暂时将 fork 的 mongod 进程的 stdout/stderr 路由到控制台

java - 如何确定我的 mysql 数据库的 url

java - 在这种情况下如何声明和使用通用映射

mongodb - 在 LoopbackJs 的属性 GeoPoint 上添加 Mongo GeoJSON 2dsphere 索引

python - pymongo $set 子文档数组

c# - 连接状态已打开但无效?

java - Eclipse : Failed to connect to remote VM. 连接被拒绝。