user2334926
user2334926

Reputation: 341

spring boot app startup failed in java 11 with gradle

I am upgrading my spring boot app from java 1.8 to java 11. I am using spring boot 1.5.12.RELEASE version and gradle 6.6.1 version. Gradle build is success but when try to run the app , i am seeing the below error. I am stuck with this from last 2 days. we have upgraded similar app from java 1.8 to 11 with same spring boot version as above but using Maven. Any help is highly appreciated. I tried in google with different solutions but could not resolve.

Task :bootRun FAILED
Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
        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:140)
        at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:583)
        at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartingEvent(RestartApplicationListener.java:67)
        at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:45)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
        at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
        at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:292)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
        at com.App.main(App.java:16)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

Upvotes: 0

Views: 1282

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116091

Spring Boot 1.5 is not compatible with Java 11. It's also no longer supported. You can either stick with Java 8 and continue to use Spring Boot 1.5 or upgrade to Spring Boot 2.3.x or 2.4.x which both support Java 11 (in addition to still supporting Java 8).

Upvotes: 2

Related Questions