Spring Bootアプリケーションの実行ができない
解決したいこと
独学でJavaの基礎の学習が終わり、「後悔しないためのSpring Boot 入門書:Spring 解体新書(第2版)Spring Bootが丸分かり」にてSpringBoot学習を始めたばかりの初心者です。
右も左も分からない状態ですが、初めてQiitaにて質問をさせていただきます。
現在、第3章の下記の写真のように「データベースから値を取得する」の学習をしています。
使用IDE : Eclipse
Spring Boot version : 2.4.1(書籍と同じものを使用)
SpringBootを実行したところ、このようなエラーが発生しました。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
[32m :: Spring Boot :: [39m [2m (v2.4.1)[0;39m
[2m2021-10-23 09:44:40.284[0;39m [32m INFO[0;39m [35m44022[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mcom.example.SpringBootSampleApplication [0;39m [2m:[0;39m Starting SpringBootSampleApplication using Java 17-beta on Kazuki-MacBook-Pro-2.local with PID 44022 (/Applications/Eclipse_2021-09.app/Contents/workspace/SpringBootSample/target/classes started by kazukiohshiro in /Applications/Eclipse_2021-09.app/Contents/workspace/SpringBootSample)
[2m2021-10-23 09:44:40.286[0;39m [32m INFO[0;39m [35m44022[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mcom.example.SpringBootSampleApplication [0;39m [2m:[0;39m No active profile set, falling back to default profiles: default
[2m2021-10-23 09:44:40.323[0;39m [32m INFO[0;39m [35m44022[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36m.e.DevToolsPropertyDefaultsPostProcessor[0;39m [2m:[0;39m Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
[2m2021-10-23 09:44:40.323[0;39m [32m INFO[0;39m [35m44022[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36m.e.DevToolsPropertyDefaultsPostProcessor[0;39m [2m:[0;39m For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
[2m2021-10-23 09:44:40.392[0;39m [33m WARN[0;39m [35m44022[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mConfigServletWebServerApplicationContext[0;39m [2m:[0;39m Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/Applications/Eclipse_2021-09.app/Contents/workspace/SpringBootSample/target/classes/com/example/SpringBootSampleApplication.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [/Applications/Eclipse_2021-09.app/Contents/workspace/SpringBootSample/target/classes/com/example/SpringBootSampleApplication.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
[2m2021-10-23 09:44:40.448[0;39m [31mERROR[0;39m [35m44022[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/Applications/Eclipse_2021-09.app/Contents/workspace/SpringBootSample/target/classes/com/example/SpringBootSampleApplication.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [/Applications/Eclipse_2021-09.app/Contents/workspace/SpringBootSample/target/classes/com/example/SpringBootSampleApplication.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:452) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:315) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:276) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:207) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:175) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:336) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:252) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:285) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:99) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:751) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:569) ~[spring-context-5.3.2.jar:5.3.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.1.jar:2.4.1]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.1.jar:2.4.1]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.1.jar:2.4.1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.1.jar:2.4.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.1.jar:2.4.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) ~[spring-boot-2.4.1.jar:2.4.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298) ~[spring-boot-2.4.1.jar:2.4.1]
at com.example.SpringBootSampleApplication.main(SpringBootSampleApplication.java:10) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.1.jar:2.4.1]
Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [/Applications/Eclipse_2021-09.app/Contents/workspace/SpringBootSample/target/classes/com/example/SpringBootSampleApplication.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:60) ~[spring-core-5.3.2.jar:5.3.2]
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:49) ~[spring-core-5.3.2.jar:5.3.2]
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) ~[spring-core-5.3.2.jar:5.3.2]
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123) ~[spring-core-5.3.2.jar:5.3.2]
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:429) ~[spring-context-5.3.2.jar:5.3.2]
... 26 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 61
at org.springframework.asm.ClassReader.<init>(ClassReader.java:189) ~[spring-core-5.3.2.jar:5.3.2]
at org.springframework.asm.ClassReader.<init>(ClassReader.java:170) ~[spring-core-5.3.2.jar:5.3.2]
at org.springframework.asm.ClassReader.<init>(ClassReader.java:156) ~[spring-core-5.3.2.jar:5.3.2]
at org.springframework.asm.ClassReader.<init>(ClassReader.java:277) ~[spring-core-5.3.2.jar:5.3.2]
at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:57) ~[spring-core-5.3.2.jar:5.3.2]
... 30 common frames omitted
ログにアプリケーションの実行に失敗しているとありますが、何をどのように対処すればいいのか分かりません。
しかし、こちらの警告が出ているところに「おそらく、まだサポートされていない新しいJavaクラスファイルのバージョンが原因です」とありますが、その対処方法が分かりません。
[2m2021-10-23 09:44:40.392[0;39m [33m WARN[0;39m [35m44022[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mConfigServletWebServerApplicationContext[0;39m [2m:[0;39m Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/Applications/Eclipse_2021-09.app/Contents/workspace/SpringBootSample/target/classes/com/example/SpringBootSampleApplication.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [/Applications/Eclipse_2021-09.app/Contents/workspace/SpringBootSample/target/classes/com/example/SpringBootSampleApplication.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
ディレクトリ一覧
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>SpringBootSample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootSample</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
自分で試したこと
springbootの実行において、ログに書かれているエラーの意味を調べたりしましたが、よく分かりませんでした。
質問のしかたが正しいのかどうかすら不安ではありますが、どなたか教えていただけませんでしょうか。
よろしくお願いいたします。