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.<init(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)
-
3Can you be more specific with your question?Phenomenal One– Phenomenal One2018-09-18 11:33:46 +00:00Commented Sep 18, 2018 at 11:33
-
3With just the stack trace is impossible to answer. Sharing your code would make it easierf-CJ– f-CJ2018-09-18 11:52:30 +00:00Commented Sep 18, 2018 at 11:52
-
Despite the departure from the rules, comments and the closure of the question, the question for those who are in the same situation is clear. Thank you author!S.Daineko– S.Daineko2020-05-26 16:52:45 +00:00Commented May 26, 2020 at 16:52
4 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.
5 Comments
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.
1 Comment
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
Comments
Check your JAVA_HOME in hadoop-env.sh. Changing my JAVA_HOME value in $HADOOP_HOME/etc/hadoop with java 8 (export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64) value in the hadoop-env.sh solved this issue for me.
I had a higher java version defined in my hadoop-env.sh value when I had defined java 8 in my .bashrc file. So keeping both the same java 8 version fixed the issue for me.