Exception in thread "main" java.lang.ClassCastException: java.base/jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to java.base/java.net.URLClassLoader at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getUrls(DefaultRestartInitializer.java:93) at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getInitialUrls(DefaultRestartInitializer.java:56) at org.springframework.boot.devtools.restart.Restarter.(Restarter.java:138) at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:537) at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartedEvent(RestartApplicationListener.java:68) at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:45) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121) at org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:63) at org.springframework.boot.SpringApplicationRunListeners.started(SpringApplicationRunListeners.java:48) at org.springframework.boot.SpringApplication.run(SpringApplication.java:304) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) at com.rme.hub.RmeApplication.main(RmeApplication.java:24)
3 Answers
Judging by the presence of java.base/jdk.internal.loader.ClassLoaders
in the stack trace, you are using Java 9 or later. Spring Boot's DefaultRestartInitializer
is trying to cast the app class loader to a URLClassLoader
. This works in Java 8 and earlier but does not work with Java 9 or later. Spring Boot had been updated in 2.0 to cope with this change in Java 9.
If you want to use Spring Boot with Java 9 or later, you should upgrade to Spring Boot 2. At the time of writing, the latest release is 2.0.5 which supports Java 8, 9, and 10. Spring Boot 2.1, which will be released later this year, will add support for Java 11.
I had this problema on eclipse and had solved by doing these step:
- First download java 8 (If you don't have) then install it
- Second, I am not sure if you have to do it or not but just do it. I create JAVA_HOME path by right click to my desktop -> properties -> Advanced System Setting -> Advanced Tab -> Environment Variables -> Add JAVA_HOME in both User Variables and System Variables -> Click new -> Variable Home is "JAVA_HOME", Variable Value can be left empty -> Browse Directory -> point to your jdk folder (Exmaple: mine is C:\Program Files\Java\jdk1.8.0_291)
- Third, go to eclipse -> go to window tab -> choose java on the menu on the left side -> Installed JREs -> in default eclipse already had jre directory -> click to it and then click duplicate -> change the directory to your own jre directory (example: C:\Program Files\Java\jre1.8.0_291)
- Forth: back to java menu, choose compiler option -> then on the right side -> change compiler compliance level to 1.8.
That is all! Hope it will be useful for you.
solution: change JDK version 8 in your IDE
I got the same issue in the spring boot application in IntelliJ idea and sts but I found one solution in that issue :
if you are using AD integration in your project with it belongs to Microsoft, then you need to use java 8 version JDK because currently Microsoft AD plugins are not supported to java 9 or higher version it will support only the java 8 or lower version