MongoCommandException:命令失败并出现错误 8000 (AtlasError):“未发送 SNI 名称,请确保使用 MongoDB 3.4+ 驱动程序/shell."

2022-01-24 00:00:00 connection mongodb java

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

I'm using Java 11 (Maven project) for mongodb Free Tier Cluster (Version 4.0.13). I'm trying to connect via connection-string (for 3.6 drivers or later) like:

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

同样通过连接字符串(对于 3.4 驱动程序或更高版本):

and by the same way via connection-string (for 3.4 driver or later):

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 (ver. 3.11.0), mongodb-driver-sync (ver. 3.10.0), mongodb-driver-sync (ver. 3.8).0).

I've already tested different dependencies for java drivers like: mongodb-driver-sync (ver. 3.11.0), mongodb-driver-sync (ver. 3.10.0) , mongodb-driver-sync (ver. 3.8.0).

Maven 依赖如下所示:

Maven dependency looks like this:

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

Also I tried to use mongo-java-driver via connection-string for 3.6 or later drivers/3.4 or later and versions like: 3.11.0, 3.10.0, 3.8.0, 3.7.0.

Maven 依赖如下所示:

Maven dependency looks like this:

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

我总是遇到同样的问题:

And I'm getting always the same issue:

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 是:

My current POM is:

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

任何解决问题的想法都将不胜感激.

Any ideas how to solve the issue will be appreciated.

推荐答案

Java 8

我已将 Java 11 更改为 Java 8,它解决了这个问题.看起来 Java 11 不支持 SNI.因为尽管我使用了最新的驱动程序,但所有尝试都没有成功.

I've changed Java 11 to Java 8 and it solved the issue. Looks like Java 11 doesn't support SNI. Because all attempts were unsuccessful despite the fact that I used the latest drivers.

Java 11

感谢 Virg 的澄清,我更改了 Java 11 的版本,还更改了许可证.我有 Java 11,使用 Java Development Kit builds (from Oracle) - 作为源.然后我安装了另一个许可证 Azulu使用JDK 11.0.5+10版本,也解决了这个错误.

Thanks to clarification by Virg, I've changed version of Java 11, but also the license. I had Java 11 using Java Development Kit builds (from Oracle) - as sourse. Then I've installed another license as Azulu using JDK version 11.0.5+10 and it also solved the error.

相关文章