環境構築

Spring Boot 3 系を前提に、Java 21 + Maven で最小 API プロジェクトを作成します。

前提ツール

バージョン確認

java -version
mvn -v

プロジェクト作成

Spring Initializr で次の依存を選択します。

pom.xml のイメージ:

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

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>
</dependencies>

ディレクトリ構成

src/main/java/com/example/demo
├── DemoApplication.java
├── controller/
├── service/
├── repository/
└── entity/

src/main/resources
├── application.yml
└── data.sql

起動確認

mvn spring-boot:run

起動後にヘルスチェック用 API を用意している場合:

curl http://localhost:8080/api/health

実務ではローカル DB(PostgreSQL など)を使うケースが多いですが、学習初期は H2 の方が環境依存を減らせます。