【问题标题】:spring boot app startup failed in java 11 with gradle带有gradle的java 11中的spring boot应用程序启动失败
【发布时间】:2021-05-15 12:33:45
【问题描述】:

我正在将我的 spring boot 应用程序从 java 1.8 升级到 java 11。我正在使用 spring boot 1.5.12.RELEASE 版本和 gradle 6.6.1 版本。 Gradle 构建成功,但是当尝试运行应用程序时,我看到以下错误。从过去的两天开始,我一直坚持这一点。我们已将类似的应用程序从 java 1.8 升级到 11,具有与上述相同的 Spring Boot 版本,但使用 Maven。非常感谢任何帮助。我在 google 中尝试了不同的解决方案,但无法解决。

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

【问题讨论】:

  • 也升级spring-boot。

标签: java spring spring-boot java-11


【解决方案1】:

Spring Boot 1.5 与 Java 11 不兼容。它也不再受支持。您可以坚持使用 Java 8 并继续使用 Spring Boot 1.5,也可以升级到都支持 Java 11 的 Spring Boot 2.3.x 或 2.4.x(除了仍然支持 Java 8)。

【讨论】:

  • 感谢@Andy Wilkinson 的快速回复。但是我们能够将 1.5.12 中的其他 spring boot 应用程序迁移到 java 11 。但是我们使用的是 Maven 而不是 gradle。这也很重要吗?
  • 不,构建系统无关紧要。您看到的具体问题是 Devtools。也许您的基于 Maven 的项目没有使用它?无论哪种方式,Spring Boot 1.5 都不支持 Java 11,即使它碰巧可以工作,你也不应该依赖它,因为它从未经过测试。
猜你喜欢
  • 2017-05-12
  • 2019-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-24
  • 2019-01-31
  • 1970-01-01
  • 2021-06-06
相关资源
最近更新 更多