Spring 初期プロジェクトの作成

Spring Initializr

Spring Initializr は、条件に合わせて初期 Spring Boot プロジェクトを生成する Web サービスである。Web UI でプロジェクト設定と使用する Spring Project を指定すると、Spring Boot プロジェクト開発を簡単に始めることができる。

curl を使用した Spring Initializr

Spring の検証などで何度もプロジェクトをスキャフォールドまたはビルドする場合、Web UI での作業は手間がかかる。そのため、ここでは curl を使用して Spring Initializr の API にアクセスし、初期プロジェクトを作成する。

% curl https://start.spring.io/
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
:: Spring Initializr ::  https://start.spring.io

This service generates quickstart projects that can be easily customized.
Possible customizations include a project's dependencies, Java version, and
build system or build structure. See below for further details.

The services uses a HAL based hypermedia format to expose a set of resources
to interact with. If you access this root resource requesting application/json
as media type the response will contain the following links:
+-----------------+------------------------------------------+
| Rel             | Description                              |
+-----------------+------------------------------------------+
| gradle-build    | Generate a Gradle build file.            |
| gradle-project  | Generate a Gradle based project archive. |
| maven-build     | Generate a Maven pom.xml.                |
| maven-project * | Generate a Maven based project archive. |
+-----------------+------------------------------------------+


The URI templates take a set of parameters to customize the result of a request
to the linked resource.
+-----------------+------------------------------------------+------------------------------+
| Parameter       | Description                              | Default value                |
+-----------------+------------------------------------------+------------------------------+
| applicationName | application name                         | DemoApplication              |
| artifactId      | project coordinates (infer archive name) | demo                         |
| baseDir         | base directory to create in the archive  | no base dir                  |
| bootVersion     | spring boot version                      | 2.7.2                        |
| dependencies    | dependency identifiers (comma-separated) | none                         |
| description     | project description                      | Demo project for Spring Boot |
| groupId         | project coordinates                      | com.example                  |
| javaVersion     | language level                           | 17                           |
| language        | programming language                     | java                         |
| name            | project name (infer application name)    | demo                         |
| packageName     | root package                             | com.example.demo             |
| packaging       | project packaging                        | jar                          |
| type            | project type                             | maven-project                |
| version         | project version                          | 0.0.1-SNAPSHOT               |
+-----------------+------------------------------------------+------------------------------+

... 省略 ...

Examples:

To create a default demo.zip:
	$ curl -G https://start.spring.io/starter.zip -o demo.zip

To create a web project using Java 11:
	$ curl -G https://start.spring.io/starter.zip -d dependencies=web \
			-d javaVersion=11 -o demo.zip

To create a web/data-jpa gradle project unpacked:
	$ curl -G https://start.spring.io/starter.tgz -d dependencies=web,data-jpa \
		   -d type=gradle-project -d baseDir=my-dir | tar -xzvf -

To generate a Maven POM with war packaging:
	$ curl -G https://start.spring.io/pom.xml -d packaging=war -o pom.xml