Problem
If you are using Spring boot v3.0 or above, then you might also come across the below error
class file has wrong version 61.0, should be 52.0
Or below
java.lang.UnsupportedClassVersionError: org/springframework/boot/SpringApplication 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 55.0
Spring boot 3 or Spring Framework 6 supports ONLY java version 17 and above.
That is, if you are using Spring boot 3, then you MUST also use java 17 or else the application will not run.
Check out the official Spring documentation, when you can find this statement
As of Spring Framework 6.0, Spring requires Java 17+.
Java class file versions
When a java class is compiled, a class file is generated with a specific version number.
This number depends on the java compiler version used to compile the class.
Below is the table with class file versions.
Version | Java Version |
---|---|
65 | Java 21 |
64 | Java 20 |
63 | Java 19 |
62 | Java 18 |
61 | Java 17 |
60 | Java 16 |
59 | Java 15 |
58 | Java 14 |
57 | Java 13 |
56 | Java 12 |
55 | Java 11 |
54 | Java 10 |
53 | Java 9 |
52 | Java 8 |
Now, out of the two errors listed above, you can see that the
- First error has 2 versions: 61 and 52.
61 means that spring jars were compiled with java 17 while the java version on which it was being executed was java 8. - Second error has 61 and 55
61 is for spring compilation version and 55 is for java 11 on which the application was being executed.
Now, you can easily understand, why spring requires at least java 17.
This is because, its code is compiled with java 17.
Solution
As an obvious solution, if you are getting any of the above error and you are using Spring boot 3 and above, then you have no choice but to upgrade java version to minimum 17.
Otherwise, you will have to downgrade spring boot below 3.0.