Home > Software engineering >  spring-boot-starter-data-mongodb version issues
spring-boot-starter-data-mongodb version issues

Time:06-20

Caused by: java.lang.UnsupportedClassVersionError: org/bson/codecs/record/RecordCodecProvider has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 59.0 at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]

Adding spring-boot-starter-data-mongodb in pom.xml casuing the issues

4.0.0 com.infinira.fps fps-api 0.0.1-SNAPSHOT Financial planning system Financial planning system API

<parent>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.0</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <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.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>

</dependencies>

<properties>
    <java.version>1.8</java.version>
</properties>

CodePudding user response:

UnsupportedClassVersionError means that your JRE is older than the version that created the class files you are trying to use. 61 means that org/bson/codecs/record/RecordCodecProvider has been compiled with JDK 17 while 59 means that you are trying to use JRE 15 to run these class files.

You could either try to find an older version of org/bson/codecs/record/RecordCodecProvider that has been compiled with JDK 15 or older, try to compile the sources yourself (provided they do not use any features newer than JDK 15), or upgrade your JRE to 17.

As active support for JDK 15 may have ended more than a year ago (OpenJDK, other flavours may vary), while JDK 17 is LTS and will be supported until 2027 (again OpenJDK) I recommend upgrading to JRE 17.

  • Related