0

while connecting to mongodb database through springboot i'm getting following exception:

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

which is caused by : java.lang.NoClassDefFoundError:jdk/net/extendedSocketOptions this is thrown by Mongo-data-core-driver - 4.1.1 jar

The specifications of the system , and others are

  1. Windows version: 10
  2. Spring tool suite version: 2.4.3
  3. Maven-apache: 4.0.0
  4. Java version: 1.8
  5. Mongo-data-core-driver - 4.1.1

Pom.xml file

4.0.0 org.springframework.boot spring-boot-starter-parent 2.4.3 com.bel mctlsv 0.0.1-SNAPSHOT mctlsv Demo project for 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>

Exception :

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
Joundill
  • 6,828
  • 12
  • 36
  • 50
  • 1
    So alright, give us what you have tried. Pom.xml file, your code, the complete stack trace... Otherwise, we cannot help you much. Or you can just `Google` the exception and try to connect the dots :) . good luck – Aris Mar 08 '21 at 10:17
  • Googling stated that ExtendedSocketOptions is part of Java 11..yet you are 1.8.5? Also check the mongo-data-core-driver compatiblity with which versions of Java. Regards – JCompetence Mar 08 '21 at 10:25
  • @Aristotle i have added the pom.xml and exception stack please check – rakshitha n Mar 08 '21 at 10:30
  • I assume you have a properties file right? With all the config for mongodb. As I can see your pom is fine. Maybe you should try a clean install. Mostly this exception is raised when It cannot find the classpath. – Aris Mar 08 '21 at 10:47
  • please add `mvn dependency:tree` output and code triggering this error – Sunil Kumar Mar 08 '21 at 10:50
  • I did the clean install in the internet PC , and then taken the complete .m2 repository and code , while i ran the code in that pc i'm able to connect but i have to do this in the offline pc , in which i'm getting the above exception – rakshitha n Mar 08 '21 at 11:13
  • i have update the classpath also – rakshitha n Mar 08 '21 at 11:14
  • @Aristotle please check in above comments – rakshitha n Mar 08 '21 at 11:18
  • can you check the difference between .m2 folders in offline and internet PC, offline PC might not have the dependency – Sunil Kumar Mar 08 '21 at 11:27
  • Oh, now it's a totally different thing I thought you are getting things from the maven central or another online repo... Why you didn't mention that you use an offline pc.... Nah anyway. Check please the `settings.xml` maybe there isn't set the correct path to the .m2/repository. There you can change either to use the online repo or the local – Aris Mar 08 '21 at 12:41
  • i have taken the .m2/repository from internet connected pc , and placed in offline pc,In settings.xml file the path has been set properly but still that exception is coming @Aristotle – rakshitha n Mar 09 '21 at 06:32
  • @SunilKumar i have updated the repository from online pc to offline pc but the issue is still the same – rakshitha n Mar 09 '21 at 06:35
  • Hmmm, so another idea is to update your Mongo, what version you use? Online Pc and offline Pc? – Aris Mar 09 '21 at 08:36
  • okay, Mongodb server version : 4.4.4 mongoDB shell version : v4.4.4 in both online and offline pc @Aristotle – rakshitha n Mar 09 '21 at 09:36
  • 1
    I really don't have any clue then. Maybe if you provide us with your code, the MongoDB connection stuff, etc, etc, maybe then we will notice something. Now I don't know what else you can try – Aris Mar 09 '21 at 11:31

0 Answers0