親バカエンジニアのナレッジ帳

webのエンジニアをやっており、日頃の開発で詰まったことや書き残しておきたいことを載せています。

JavaのバージョンアップでSpringBootのOpenJDK 64-Bit Server VM warning:エラー

Java13以降発生するSpringBootのエラー

SpringBootを使用していてJavaのバージョンを17に上げた時、以下のエラーが発生しました。

OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
ターゲット VM に接続しました。アドレス : '127.0.0.1:58935'、トランスポート: 'ソケット'
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: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.thegate12.Application.main(Application.java:13)
ターゲット VM から切断されました。アドレス: '127.0.0.1:58935'、トランスポート: 'ソケット'

プロセスは終了コード 1 で終了しました

どうやらSpringBootのバージョン自体を上げないいけない模様。(当然ですが)

変更前は以下のように1.4.3.RELEASEのバージョンを使用していましたが、

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.4.3.RELEASE</version>
</parent>

変更後は最新の3.1.2に変更してビルドするとエラーは出なくなりました。

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>3.1.2</version>
</parent>

エラーメッセージにJDK 13 云々と書かれているので、Java13以降は同じような対応が必要かもしれませんね。
(JavaとSpringBootの対応表はちゃんと見ていませんが)