@baseball89sport

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Spring Bootの作成のエラー解消がわからないです。

Javaのアプリ開発の練習で『Spring 徹底入門』という書籍のチュートリアルを参考に
Spring Bootでの開発を進めているのですが、
中間段階のいったんアプリを起動してみようという箇所でアプリを起動したら、
エラーが出て起動できませんでした。

シンプルなJavaのソースなどは理解できているのですが、
アプリ開発は全くの無知でログを読んでもどこが原因かわからず苦戦しています。
(バージョンとかの兼ね合いでうまくいっていないのかもしれないです)

必要なファイルは書籍通りに記載できています。
現在作成したすべてのファイルを下記に載せています。

どなたか精通しているかたアドバイスをお願い致します。
どんなことでも大丈夫ですので、よろしくお願いします。
(エラーログはどこが重要かわからず、全て記載しているので一番下にあります)

application.properties
spring.application.name=mrs
spring.jpa.database=POSTGRESQL
spring.datasource.url=jdbc:postgresql://localhost:5432/mrs
spring.datasource.username=mrs
spring.datasource.password=mrs
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.format_sql=true
spring.sql.init.encoding=UTF-8
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
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>3.5.4</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>mrs</groupId>
	<artifactId>mrs</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>mrs</name>
	<description>Demo project for Spring Boot</description>
	<url/>
	<licenses>
		<license/>
	</licenses>
	<developers>
		<developer/>
	</developers>
	<scm>
		<connection/>
		<developerConnection/>
		<tag/>
		<url/>
	</scm>
	<properties>
		<java.version>17</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</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>org.postgresql</groupId>
			<artifactId>postgresql</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>
		<dependency>
			<groupId>org.thymeleaf.extras</groupId>
			<artifactId>thymeleaf-extras-java8time</artifactId>
			<version>2.1.0.RELEASE</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<annotationProcessorPaths>
						<path>
							<groupId>org.projectlombok</groupId>
							<artifactId>lombok</artifactId>
						</path>
					</annotationProcessorPaths>
				</configuration>
			</plugin>
			<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>
ThymeleafConfig.java
package mrs;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect;

@Configuration
public class ThymeleafConfig {
	@Bean
	public Java8TimeDialect java8TimeDialect() {
		return new Java8TimeDialect();
	}
}
User.java
package mrs.domain.model;

import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name="usr")
public class User {
	@Id
	private String userId;
	
	private String password;
	
	private String firstName;
	
	private String lastName;
	
	@Enumerated(EnumType.STRING)
	private RoleName roleName;

	
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
}
RoleName.java
package mrs.domain.model;

public enum RoleName {
	ADMIN, USER
}
MeetingRoom.java
package mrs.domain.model;

import java.io.Serializable;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Entity
public class MeetingRoom implements Serializable{
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer roomId;
	
	private String roomName;

	
	public String getRoomName() {
		return roomName;
	}

	public void setRoomName(String roomName) {
		this.roomName = roomName;
	}	

}
ReservableRoom.java
package mrs.domain.model;

import java.io.Serializable;

import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MapsId;

@Entity
public class ReservableRoom implements Serializable{
	@EmbeddedId
	private ReservableRoomId reservableRoomId;
	
	@ManyToOne
	@JoinColumn(name = "room_id", insertable = false, updatable = false)
	@MapsId("roomId")
	private MeetingRoom meetingRoom;

	public ReservableRoom(ReservableRoomId reservableRoomId) {
		this.reservableRoomId = reservableRoomId;
	}
	
	public ReservableRoom() {
		
	}
}
ReservableRoomId.java
package mrs.domain.model;

import java.io.Serializable;
import java.time.LocalDate;

import jakarta.persistence.Embeddable;

@Embeddable
public class ReservableRoomId implements Serializable {
	
	private Integer roomId;
	
	private LocalDate reservedDate;
	
	public ReservableRoomId(Integer roomId, LocalDate reLocalDate) {
		this.roomId = roomId;
		this.reservedDate = reLocalDate;
	}
	
	public ReservableRoomId() {
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((reservedDate == null) ? 0 : reservedDate.hashCode());
		result = prime * result + ((roomId == null) ? 0 : roomId.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(this == obj) return true;
		if(obj == null) return false;
		if(getClass() != obj.getClass()) return false;
		ReservableRoomId other = (ReservableRoomId) obj;
		if(reservedDate == null) {
			if(other.reservedDate != null) return false;
		}else if (!reservedDate.equals(other.reservedDate))
			return false;
		if(roomId == null) {
			if(other.roomId != null) return false;
		}else if (!roomId.equals(other.roomId))
			return false;
		return true;
	}

}
Reservation.java
package mrs.domain.model;

import java.time.LocalTime;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinColumns;
import jakarta.persistence.ManyToOne;

@Entity
public class Reservation {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer reservationId;
	
	private LocalTime startTime;
	
	private LocalTime endTime;

	@ManyToOne
	@JoinColumns({ @JoinColumn(name = "reserved_date"), @JoinColumn(name = "room_Id")})
	private ReservableRoom reservableRoom;
	
	@ManyToOne
	@JoinColumn(name = "user_id")
	private User user;

	
	public LocalTime getStartTime() {
		return startTime;
	}

	public void setStartTime(LocalTime startTime) {
		this.startTime = startTime;
	}

	public LocalTime getEndTime() {
		return endTime;
	}

	public void setEndTime(LocalTime endTime) {
		this.endTime = endTime;
	}
	
}
LocalDateConverter.java
package mrs.domain.model.converter;

import java.sql.Date;
import java.time.LocalDate;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class LocalDateConverter implements AttributeConverter<LocalDate, Date> {
	
	@Override
	public Date convertToDatabaseColumn(LocalDate date) {
		return date == null ? null : Date.valueOf(date);
	}
	
	@Override
	public LocalDate convertToEntityAttribute(Date value) {
		return value == null ? null : value.toLocalDate();
	}
}
LocalTimeConverter.java
package mrs.domain.model.converter;

import java.sql.Time;
import java.time.LocalTime;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class LocalTimeConverter implements AttributeConverter<LocalTime, Time>{

	@Override
	public Time convertToDatabaseColumn(LocalTime time) {
		return time == null ? null : Time.valueOf(time);
	}
	
	@Override
	public LocalTime convertToEntityAttribute(Time value) {
		return value == null ? null : value.toLocalTime();
	}
}
LocalDateTimeConverter.java
package mrs.domain.model.converter;

import java.sql.Timestamp;
import java.time.LocalDateTime;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class LocalDateTimeConverter implements AttributeConverter<LocalDateTime, Timestamp> {

	@Override
	public Timestamp convertToDatabaseColumn(LocalDateTime dateTime) {
		return dateTime == null ? null : Timestamp.valueOf(dateTime);
	}
	
	@Override
	public LocalDateTime convertToEntityAttribute(Timestamp value) {
		return value == null ? null : value.toLocalDateTime();
	}
}
schema.sql
drop table if exists meeting_room cascade;
drop table if exists reservable_room cascade;
drop table if exists reservation cascade;
drop table if exists usr cascade;

create table if not exists meeting_room(
	room_id serial not null,
	room_name varchar(255) not null,
	primary key (room_id)
);
create table if not exists reservable_room(
	reserved_date date not null,
	room_id int4 not null,
	primary key(reserved_date, room_id)
);
create table if not exists reservation(
	reservation_id serial not null,
	end_time time not null,
	start_time time not null,
	resered_date date not null,
	room_id int4 not null,
	user_id varchar(255) not null,
	primary key(reservation_id)
);
create table if not exists usr(
	user_id varchar(255) not null,
	first_name varchar(255) not null,
	last_name varchar(255) not null,
	password varchar(255) not null,
	role_name varchar(255) not null,
	primary key(user_id)
);
alter table reservable_room drop constraint if exists FK_f4wnx2qj0d59s9tl1q5800fw7;
alter table reservation drop constraint if exists FK_p1k4iriqd4eo1cpnv79uvni9g;
alter table reservation drop constraint if exists FK_recqnfjcp370rygd9hjjxjtg;
alter table reservable_room add constraint FK_f4wnx2qj0d59s9tl1q5800fw7 foreign key(room_id) references meeting_id;
alter table reservation add constraint FK_p1k4iriqd4eo1cpnv79uvni9g foreign key(reserved_date, room_id) references reservable_room;
alter table reservation add constraint FK_recqnfjcp370rygd9hjjxjtg foreign key(user_id) references usr;
ReservableRoomRepository.java
package mrs.domain.repository.room;

import java.time.LocalDate;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import mrs.domain.model.ReservableRoom;
import mrs.domain.model.ReservableRoomId;

public interface ReservableRoomRepository  extends JpaRepository<ReservableRoom, ReservableRoomId>{
	List<ReservableRoom> findByReservableRoomId_reservedDateOrderByReservableRoomId_roomIdAsc(LocalDate reservedDate);
}

```RoomService.java
package mrs.domain.service.room;

import java.time.LocalDate;
import java.util.List;

import jakarta.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import mrs.domain.model.ReservableRoom;
import mrs.domain.repository.room.ReservableRoomRepository;

@Service
@Transactional
public class RoomService {
	
	@Autowired
	ReservableRoomRepository reservableRoomRepository;
	
	public List<ReservableRoom> findReservableRooms(LocalDate date){
		return reservableRoomRepository.findByReservableRoomId_reservedDateOrderByReservableRoomId_roomIdAsc(date);
	}

}
RoomsController.java
package mrs.app.room;

import java.time.LocalDate;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import mrs.domain.model.ReservableRoom;
import mrs.domain.service.room.RoomService;

@Controller
@RequestMapping("rooms")
public class RoomsController {
	@Autowired
	RoomService roomService;
	
	@RequestMapping(method = RequestMethod.GET)
	String listRooms(Model model){
		LocalDate today = LocalDate.now();
		List<ReservableRoom> rooms = roomService.findReservableRooms(today);
		model.addAttribute("date", today);
		model.addAttribute("rooms", rooms);
		return "room/listRooms";
	}
	
	@RequestMapping(path = "{date}", method = RequestMethod.GET)
	String listRooms(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @PathVariable("date") LocalDate date, Model model) {
		List<ReservableRoom> rooms = roomService.findReservableRooms(date);
		model.addAttribute("rooms",rooms);
		return "room/listRooms";
	}
}
listRoom.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title th:text="|${#temporals.format(date, 'yyyy/M/d)}の会議室|">2016/5/20の会議室</title>
</head>
<body>
	<h3>会議室</h3>
	<a th:href="@{'/rooms/' + ${date.minusDays(1)}}">&lt; 前日</a>
	<span th:text="|${#temporals.format(date, 'yyyy/M/d')}の会議室|">2016/5/20の会議室</span>
	<a th:href="@{'/rooms/' + ${date.plusDays(1)}}">翌日 &gt;</a>
	
	<ul>
		<li th:each="room: ${rooms}">
			<a th:href="@{'/reservations/' + ${date} + '/' + ${room.meetingRoom.roomId}}"
			   th:text="${room.meetingRoom.roomName}"></a>
		</li>
	</ul>
</body>
</html>
data.sql
--会議室
insert into meeting_room(room_name) values('新木場');
insert into meeting_room(room_name) values('辰巳');
insert into meeting_room(room_name) values('豊洲');
insert into meeting_room(room_name) values('月島');
insert into meeting_room(room_name) values('新富町');
insert into meeting_room(room_name) values('銀座一丁目');
insert into meeting_room(room_name) values('有楽町');

--会議室の予約可能日
--room_id=1(新木場)
insert into reservable_room(reserved_date, room_id) values(current_date, 1);
insert into reservable_room(reserved_date, room_id) values(current_date + 1, 1);
insert into reservable_room(reserved_date, room_id) values(current_date - 1, 1);
--room_id=2(辰巳)
insert into reservable_room(reserved_date, room_id) values(current_date, 2);
insert into reservable_room(reserved_date, room_id) values(current_date + 1, 2);
insert into reservable_room(reserved_date, room_id) values(current_date - 1, 2);
--room_id=3(豊洲)
insert into reservable_room(reserved_date, room_id) values(current_date, 3);
insert into reservable_room(reserved_date, room_id) values(current_date + 1, 3);
insert into reservable_room(reserved_date, room_id) values(current_date - 1, 3);
--room_id=4(月島)
insert into reservable_room(reserved_date, room_id) values(current_date, 4);
insert into reservable_room(reserved_date, room_id) values(current_date + 1, 4);
insert into reservable_room(reserved_date, room_id) values(current_date - 1, 4);
--room_id=5(新富町)
insert into reservable_room(reserved_date, room_id) values(current_date, 5);
insert into reservable_room(reserved_date, room_id) values(current_date + 1, 5);
insert into reservable_room(reserved_date, room_id) values(current_date - 1, 5);
--room_id=6(銀座一丁目)
insert into reservable_room(reserved_date, room_id) values(current_date, 6);
insert into reservable_room(reserved_date, room_id) values(current_date + 1, 6);
insert into reservable_room(reserved_date, room_id) values(current_date - 1, 6);
--room_id=7(有楽町)
insert into reservable_room(reserved_date, room_id) values(current_date, 7);
insert into reservable_room(reserved_date, room_id) values(current_date + 1, 7);
insert into reservable_room(reserved_date, room_id) values(current_date - 1, 7);

--ダミーユーザー(password = demo)
insert into usr(user_id, first_name, last_name, password, role_name) values('taro-yamada', '太郎', '山田', 
	'$2a$10$oxSJl.keBwxmsMLkcT9lPeAIxfNTPNQxpeywMrF7A3kVszwUTqfTK', 'USER');

--認証確認用テストユーザー(password = demo)
insert into usr(user_id, first_name, last_name, password, role_name) values('aaaa', 'Aaa', 'Aaa', 
	'$2a$10$oxSJl.keBwxmsMLkcT9lPeAIxfNTPNQxpeywMrF7A3kVszwUTqfTK', 'USER');
insert into usr(user_id, first_name, last_name, password, role_name) values('bbbb', 'Bbb', 'Bbb', 
	'$2a$10$oxSJl.keBwxmsMLkcT9lPeAIxfNTPNQxpeywMrF7A3kVszwUTqfTK', 'USER');
insert into usr(user_id, first_name, last_name, password, role_name) values('cccc', 'Ccc', 'Ccc', 
	'$2a$10$oxSJl.keBwxmsMLkcT9lPeAIxfNTPNQxpeywMrF7A3kVszwUTqfTK', 'ADMIN');
Error.Log

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

[32m :: Spring Boot :: [39m              [2m (v3.5.4)[0;39m

[2m2025-08-20T22:07:26.432+09:00[0;39m [32m INFO[0;39m [35m15989[0;39m [2m--- [mrs] [  restartedMain] [0;39m[36mmrs.MrsApplication                      [0;39m [2m:[0;39m Starting MrsApplication using Java 17.0.11 with PID 15989 (/Applications/Eclipse_2024-06.app/Contents/workspace/mrs/target/classes started by yuta in /Applications/Eclipse_2024-06.app/Contents/workspace/mrs)
[2m2025-08-20T22:07:26.434+09:00[0;39m [32m INFO[0;39m [35m15989[0;39m [2m--- [mrs] [  restartedMain] [0;39m[36mmrs.MrsApplication                      [0;39m [2m:[0;39m No active profile set, falling back to 1 default profile: "default"
[2m2025-08-20T22:07:26.452+09:00[0;39m [32m INFO[0;39m [35m15989[0;39m [2m--- [mrs] [  restartedMain] [0;39m[36m.e.DevToolsPropertyDefaultsPostProcessor[0;39m [2m:[0;39m Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
[2m2025-08-20T22:07:26.452+09:00[0;39m [32m INFO[0;39m [35m15989[0;39m [2m--- [mrs] [  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'
[2m2025-08-20T22:07:26.705+09:00[0;39m [33m WARN[0;39m [35m15989[0;39m [2m--- [mrs] [  restartedMain] [0;39m[36mConfigServletWebServerApplicationContext[0;39m [2m:[0;39m Exception encountered during context initialization - cancelling refresh attempt: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
[2m2025-08-20T22:07:26.709+09:00[0;39m [32m INFO[0;39m [35m15989[0;39m [2m--- [mrs] [  restartedMain] [0;39m[36m.s.b.a.l.ConditionEvaluationReportLogger[0;39m [2m:[0;39m 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
[2m2025-08-20T22:07:26.718+09:00[0;39m [31mERROR[0;39m [35m15989[0;39m [2m--- [mrs] [  restartedMain] [0;39m[36mo.s.boot.SpringApplication              [0;39m [2m:[0;39m Application run failed

java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-3.5.4.jar:3.5.4]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:99) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:183) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:430) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:290) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:349) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:118) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609) ~[spring-context-6.2.9.jar:6.2.9]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.5.4.jar:3.5.4]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-3.5.4.jar:3.5.4]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.5.4.jar:3.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-3.5.4.jar:3.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361) ~[spring-boot-3.5.4.jar:3.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) ~[spring-boot-3.5.4.jar:3.5.4]
	at mrs.MrsApplication.main(MrsApplication.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:50) ~[spring-boot-devtools-3.5.4.jar:3.5.4]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [mrs.ThymeleafConfig] from ClassLoader [org.springframework.boot.devtools.restart.classloader.RestartClassLoader@5a775e3e]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483) ~[spring-core-6.2.9.jar:6.2.9]
	at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:360) ~[spring-core-6.2.9.jar:6.2.9]
	at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:417) ~[spring-core-6.2.9.jar:6.2.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$1(AbstractAutowireCapableBeanFactory.java:757) ~[spring-beans-6.2.9.jar:6.2.9]
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:756) ~[spring-beans-6.2.9.jar:6.2.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:689) ~[spring-beans-6.2.9.jar:6.2.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:660) ~[spring-beans-6.2.9.jar:6.2.9]
	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1716) ~[spring-beans-6.2.9.jar:6.2.9]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:639) ~[spring-beans-6.2.9.jar:6.2.9]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:611) ~[spring-beans-6.2.9.jar:6.2.9]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:596) ~[spring-beans-6.2.9.jar:6.2.9]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanDefinitionsForType(OnBeanCondition.java:322) ~[spring-boot-autoconfigure-3.5.4.jar:3.5.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanDefinitionsForType(OnBeanCondition.java:314) ~[spring-boot-autoconfigure-3.5.4.jar:3.5.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:214) ~[spring-boot-autoconfigure-3.5.4.jar:3.5.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.evaluateConditionalOnMissingBean(OnBeanCondition.java:197) ~[spring-boot-autoconfigure-3.5.4.jar:3.5.4]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:144) ~[spring-boot-autoconfigure-3.5.4.jar:3.5.4]
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-3.5.4.jar:3.5.4]
	... 22 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/thymeleaf/dialect/IExpressionEnhancingDialect
	at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017) ~[na:na]
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na]
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862) ~[na:na]
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760) ~[na:na]
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681) ~[na:na]
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639) ~[na:na]
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[na:na]
	at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
	at java.base/java.lang.Class.forName(Class.java:467) ~[na:na]
	at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:121) ~[spring-boot-devtools-3.5.4.jar:3.5.4]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[na:na]
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402) ~[na:na]
	at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504) ~[na:na]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465) ~[spring-core-6.2.9.jar:6.2.9]
	... 39 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.thymeleaf.dialect.IExpressionEnhancingDialect
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[na:na]
	... 56 common frames omitted



0 likes

3Answer

Spring Boot と Thymeleaf のバージョン不整合な感じがします。
↓ 参考になりませんか。

1Like

Comments

  1. 他の方からのコメントでJava8Timeが原因という指摘を受けたので調べてみたら、Spring Boot 3以降とJava8Timeは互換性がなく使用できないとのことでした。

    ThymeleafConfig.java自体が要らなかったらしく、削除したら今回のエラーは無くなりました。
    (表示がうまくいかないエラーと格闘中です)

    アドバイスありがとうございました。

ざっくりで恐れ入りますが回答します。

スタックトレースを下から辿っていくと、

Caused by: java.lang.NoClassDefFoundError: org/thymeleaf/dialect/IExpressionEnhancingDialect

で存在しないか、サポートしていないクラスを
呼び出そうとして落ちているように見えます。

Caused by: java.lang.IllegalStateException: Failed to introspect Class [mrs.ThymeleafConfig] from ClassLoader [org.springframework.boot.devtools.restart.classloader.RestartClassLoader@5a775e3e]

元はmrs.ThymeleafConfigを読み込んでいる時に起きていそうです。

肝心の箇所を見てみると

ThymeleafConfig.java
package mrs;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect;

となっており、ここで以下を確認してみて思ったことですが、

pom.xml
     <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.5.4</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	・
    ・
    ・
    (中略)
    ・
    ・
    ・
	<dependencies>
		<dependency>
			<groupId>org.thymeleaf.extras</groupId>
			<artifactId>thymeleaf-extras-java8time</artifactId>
			<version>2.1.0.RELEASE</version>
		</dependency>
	</dependencies>

Spring Boot 3.x系
Thymeleaf 2.x系の互換性はありますか?

確信が無いようであれば
確認してみることをおすすめします。

参考情報が見つかるかは分かりませんが、
thymeleaf-extras-java8timeのGitHub情報も提示しておきます。

私も「Spring 徹底入門」は過去に
初版を読みながら色々試した記憶が薄っすらありますが…
今確認したところ、最新の第2版でも1年以上前の情報のように見受けられるので

必要なファイルは書籍通りに記載できています。

といっても
記載内容と現在更新されている技術の差分に気を付ける必要がありそうです。

1Like

Comments

  1. 他の方からのコメントでJava8Timeが原因という指摘を受けたので調べてみたら、Spring Boot 3以降とJava8Timeは互換性がなく使用できないとのことでした。

    ThymeleafConfig.java自体が要らなかったらしく、削除したら今回のエラーは無くなりました。
    (表示がうまくいかないエラーと格闘中です)

    少し古い書籍だとそのまま書いてもうまくいかないことがあるんですね。
    ほとんどわからない状態なので、少しずつ頑張っていこうと思います。

    アドバイスありがとうございました。

動かすだけであればThymeleafConfig.javaを削除すれば起動に成功すると思います。
最近のSpring bootだとJava8TimeDialectは自動的に登録されるっぽいです。
参考 : 最近の SpringBootで thymeleaf-extras-java8time を利用する際、 @Configuration なクラスは不要 - end0tknr's kipple - web写経開発

最小構成のSpring bootプロジェクトにthymeleaf-extras-java8timeの依存関係を追加し、Configのあるなしを試してみましたが確かに記事の通りとなりました。

1Like

Comments

  1. ThymeleafConfig.javaを削除したら、起動までエラーなしで行けるようになりました。

    まだ全然わからず写しながら理解していこうと思っているので、教えていただけるととてもありがたいです。
    画面の表示の方はまだうまくいっていないので、頑張ります。

    アドバイスありがとうございました。

Your answer might help someone💌