0

通过springboot连接到mongodb数据库时出现以下异常:

com.mongodb.mongoexception:java.lang.NoClassDefFoundError:jdk/net/ExtendedSocketOptions

这是由以下原因引起的:java.lang.NoClassDefFoundError:jdk/net/extendedSocketOptions 这是由 Mongo-data-core-driver - 4.1.1 jar 抛出的

系统规格等

  1. 视窗版本:10
  2. Spring工具套件版本:2.4.3
  3. Maven-阿帕奇:4.0.0
  4. Java版本:1.8
  5. Mongo-data-core-driver - 4.1.1

Pom.xml 文件

4.0.0 org.springframework.boot spring-boot-starter-parent 2.4.3 com.bel mctlsv 0.0.1-SNAPSHOT mctlsv Spring Boot <java.version>1.8</java.version>的演示项目

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId> 
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

例外 :

com.mongodb.MongoException: java.lang.NoClassDefFoundError: jdk/net/ExtendedSocketOptions
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:157) ~[mongodb-driver-core-4.1.1.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) ~[mongodb-driver-core-4.1.1.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.1.1.jar:na]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_05]
Caused by: java.lang.NoClassDefFoundError: jdk/net/ExtendedSocketOptions
    at com.mongodb.internal.connection.SocketStreamHelper.setExtendedSocketOptions(SocketStreamHelper.java:83) ~[mongodb-driver-core-4.1.1.jar:na]
    at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:53) ~[mongodb-driver-core-4.1.1.jar:na]
    at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[mongodb-driver-core-4.1.1.jar:na]
    at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-4.1.1.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:143) ~[mongodb-driver-core-4.1.1.jar:na]
    ... 3 common frames omitted
4

0 回答 0