
# すべてのプロパティ

`spring_boot_starter_data` が読むすべてのプロパティを、プレフィックスごとにまとめています。各行には、キー、その型と指定できる値、デフォルト、働きを示します。スターターのメタデータ (`lib/spring_gen/spring_metadata.json`) にも同じキーが列挙されているため、補完機能のあるエディターでも候補に出ます。プライマリーのデータベースとスターターの 58 個のキーと、名前付きのデータベースのための `spring.datasources.*` の下の 44 個のキーです。

## 使う理由

データ層は、ほとんどすべてプロパティで設定します。どのデータベースか、接続はいくつか、どのマイグレーションか、何をログに出すかです。このページはそのすべてを列挙した唯一の場所で、すべてのページを読まなくても、キー、その型、そのデフォルトを確認できます。

## 例

実際的な設定です。本番では TLS 付きの PostgreSQL、統計のための SQLite の副データベース、データベースごとのマイグレーション、遅い文のログ、API のためのページングの上限です。

```yaml
# lib/resources/application.yml
spring:
  datasource:
    url: postgresql://db.example.com:5432/shop
    username: shop
    password: ${SHOP_DB_PASSWORD}
    pool:
      max-size: 20
      min-idle: 2
      connection-timeout: 10s
      idle-timeout: 10m
      max-lifetime: 30m
      validation: true
    postgresql:
      sslmode: verify-full
      ssl-root-cert: /etc/ssl/certs/db-ca.pem
      connect-timeout: 5s
      application-name: shop-api
      search-path: shop,public
  datasources:
    stats:
      url: sqlite:file:stats.db
      sqlite:
        busy-timeout: 2000
        isolate: true
      sql:
        migration:
          locations: resources:db/stats
  sql:
    migration:
      locations: resources:db/migration/{vendor}
      connect-retries: 5
      connect-retries-interval: 5s
      placeholders:
        recent-year: '2000'
  data:
    jdbc:
      schema: validate
      slow-query-threshold: 500ms
    web:
      pageable:
        default-page-size: 20
        max-page-size: 100
  jdbc:
    template:
      query-timeout: 30s
```

同じ内容を `.properties` で:

```properties
# lib/resources/application.properties
spring.datasource.url=postgresql://db.example.com:5432/shop
spring.datasource.username=shop
spring.datasource.password=${SHOP_DB_PASSWORD}
spring.datasource.pool.max-size=20
spring.datasource.pool.min-idle=2
spring.datasource.pool.connection-timeout=10s
spring.datasource.pool.idle-timeout=10m
spring.datasource.pool.max-lifetime=30m
spring.datasource.pool.validation=true
spring.datasource.postgresql.sslmode=verify-full
spring.datasource.postgresql.ssl-root-cert=/etc/ssl/certs/db-ca.pem
spring.datasource.postgresql.connect-timeout=5s
spring.datasource.postgresql.application-name=shop-api
spring.datasource.postgresql.search-path=shop,public
spring.datasources.stats.url=sqlite:file:stats.db
spring.datasources.stats.sqlite.busy-timeout=2000
spring.datasources.stats.sqlite.isolate=true
spring.datasources.stats.sql.migration.locations=resources:db/stats
spring.sql.migration.locations=resources:db/migration/{vendor}
spring.sql.migration.connect-retries=5
spring.sql.migration.connect-retries-interval=5s
spring.sql.migration.placeholders.recent-year=2000
spring.data.jdbc.schema=validate
spring.data.jdbc.slow-query-threshold=500ms
spring.data.web.pageable.default-page-size=20
spring.data.web.pageable.max-page-size=100
spring.jdbc.template.query-timeout=30s
```

## 値の書き方

- **期間:** `500ms`、`30s`、`10m`、`1h`、ISO 8601 (`PT30S`)、または単なるミリ秒の数値。`spring.datasource.postgresql.connect-timeout` は `PT30S` を受け取りません。[Durations](../spring-core-dart/conversion/durations.md) を参照してください。
- **リスト:** `.properties` ではカンマ区切り (`a,b`)、YAML では YAML のリストかカンマ区切り。
- **環境変数:** `SPRING_DATASOURCE_URL`、`SPRING_DATASOURCE_POSTGRESQL_SSLMODE`、`SPRING_DATASOURCES_STATS_SQLITE_BUSYTIMEOUT`。`spring.datasources.<name>` の名前は、キーを列挙するプロパティソース (ファイル、コマンドライン) の中でだけ見つけられます。URL をファイルで宣言し、変数で上書きしてください。

## spring.datasource: プライマリーのデータベース

`spring.datasource.url` を設定すると、スターターはプライマリーの `DataSource` とその上の Bean を作ります。それがなければ、リポジトリはデータをメモリに保持します。

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.datasource.url` | `String` | なし | データベースの URL: `sqlite:file:books.db`、`sqlite::memory:`、または `postgresql://user:password@host:5432/db`。先頭の `jdbc:` は取り除かれる。スキームがドライバーを選ぶ。挙げたどのドライバーも扱わないスキームは起動を止める。 |
| `spring.datasource.username` | `String` | なし | URL が持たないときのデータベースのユーザー。 |
| `spring.datasource.password` | `String` | なし | URL が持たないときのデータベースのパスワード。決してログに出されない。 |
| `spring.datasource.driver` | `String` | なし | 2 つのドライバーがスキームを扱うときのドライバーの名前 (`sqlite3`、`postgres`)。 |

## spring.datasource.pool

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.datasource.pool.max-size` | `int` | `10` | 同時に持つ最大の接続数。1 以上。 |
| `spring.datasource.pool.min-idle` | `int` | `0` | アイドル時に開いておく接続。0 から `max-size` まで。 |
| `spring.datasource.pool.connection-timeout` | `Duration` | `30s` | 接続を待つ最長時間。その後 `CannotGetJdbcConnectionException`。 |
| `spring.datasource.pool.idle-timeout` | `Duration` | `10m` | これより長くアイドルな `min-idle` を超える接続は閉じられる。`0` は永久に保つ。 |
| `spring.datasource.pool.max-lifetime` | `Duration` | `30m` | これより古い接続は、プールに戻ったときに閉じられる。上限なしは `0`。 |
| `spring.datasource.pool.validation` | `bool` | `true` | プールで待っていた接続を、渡す前に `isValid` でチェックするかどうか。 |

## spring.datasource.sqlite

`spring.datasource.sqlite3.*` としても読めます (ドライバーの名前が優先されます)。[SQLite](sqlite.md) を参照してください。

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.datasource.sqlite.busy-timeout` | `int` | `5000` | 接続が SQLite のロックを待つミリ秒。 |
| `spring.datasource.sqlite.base-directory` | `String` | 作業ディレクトリ | 相対の `sqlite:file:` の名前を探す場所。`SqliteJdbcDriver.baseDirectory` より優先される。Flutter アプリでは Flutter スターターが設定する。 |
| `spring.datasource.sqlite.isolate` | `bool` | `false` | `true` は各接続を専用の Isolate の中で開くため、長いクエリやビジーの待機が呼び出し元の Isolate を止めない。`SqliteJdbcDriver(isolate:)` より優先される。Flutter アプリでは Flutter スターターが `true` に設定する。 |
| `spring.datasource.sqlite.location` | `support`、`cache`、`documents` | `support` | `spring_boot_starter_flutter` だけが読む: `base-directory` に設定するアプリのディレクトリ。それ以外の値は起動を止める。このスターターのメタデータにはない。 |

## spring.datasource.postgresql

`spring.datasource.postgres.*` としても読めます (ドライバーの名前が優先されます)。URL のパラメーター `sslmode`、`sslrootcert`、`connect_timeout`、`application_name`、`currentSchema` は同じものを設定し、プロパティが優先されます。[PostgreSQL](postgresql.md) を参照してください。

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.datasource.postgresql.sslmode` | `disable`、`allow`、`prefer`、`require`、`verify-ca`、`verify-full` | `prefer` | 接続が TLS を使うかどうかとその方法 (libpq の `sslmode`)。`allow` は `prefer` と同じくまず TLS を試す。`verify-ca` は `verify-full` と同じく厳格。 |
| `spring.datasource.postgresql.ssl-root-cert` | `String` | システムのルート | `verify-*` モードがサーバーを照合する認証局の PEM ファイル。 |
| `spring.datasource.postgresql.connect-timeout` | `Duration` | `15s` | 接続と TLS ハンドシェイクを待つ最長時間 (`500ms`、`30s`、`1m`、またはミリ秒。`PT30S` は不可)。 |
| `spring.datasource.postgresql.application-name` | `String` | なし | `pg_stat_activity` に表示される。 |
| `spring.datasource.postgresql.search-path` | `String` | サーバーのもの | `search_path` のスキーマ。カンマ区切り (URL の `currentSchema`)。 |

## spring.datasources: 名前付きのデータベース

各 `spring.datasources.<name>.url` はデータベースを追加し、修飾子 `<name>` の Bean (`<name>DataSource`、`<name>TransactionManager`、`<name>JdbcTemplate`、`<name>NamedParameterJdbcTemplate`、`<name>JdbcClient`) を持ちます。`@UseDataSource('<name>')` と `@Transactional(transactionManager: '<name>')` で使います。プライマリーのデータベースのすべてのキーと、独自のスキーマの設定を受け取ります。

| キー | 同じもの |
|---|---|
| `spring.datasources.<name>.url`、`.username`、`.password`、`.driver` | `spring.datasource.*` |
| `spring.datasources.<name>.pool.*` (6 個のキー) | `spring.datasource.pool.*` |
| `spring.datasources.<name>.sqlite.busy-timeout`、`.base-directory`、`.isolate` | `spring.datasource.sqlite.*` |
| `spring.datasources.<name>.postgresql.*` (5 個のキー) | `spring.datasource.postgresql.*` |
| `spring.datasources.<name>.sql.init.*` (7 個のキー) | `spring.sql.init.*` |
| `spring.datasources.<name>.sql.migration.*` (18 個のキー) | `spring.sql.migration.*` |
| `spring.datasources.<name>.data.jdbc.schema` | `spring.data.jdbc.schema` |

デフォルトはプライマリーのデータベースと同じです。名前付きのデータベースは、プライマリーの値を継承しません。

## spring.sql.migration: マイグレーション

[スキーマとマイグレーション](schema.md) を参照してください。Spring Boot の `spring.flyway.*` の名前は、これらを示して起動を止めます。

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.sql.migration.enabled` | `bool` | `true` | マイグレーション (`V<version>__<name>.sql` と `R__<name>.sql`) を実行するかどうか。ファイルがなければ、いずれにせよ何も実行されない。 |
| `spring.sql.migration.locations` | `List<String>` | `resources:db/migration` | ファイルの場所。`{vendor}` は方言の名前 (`sqlite`、`postgresql`) に置き換えられる。 |
| `spring.sql.migration.table` | `String` | `schema_history` | 履歴テーブル。 |
| `spring.sql.migration.validate-on-migrate` | `bool` | `true` | チェックサムが変わった、またはファイルにない適用済みのマイグレーションや、適用済みのものより古い未適用のファイルが、起動を止めるかどうか。 |
| `spring.sql.migration.target` | `String` | `latest` | マイグレーションの目標バージョン、または `latest`。繰り返し可能なマイグレーションは `latest` でだけ実行される。 |
| `spring.sql.migration.out-of-order` | `bool` | `false` | 最新の適用済みのものより低いバージョンのファイルも実行するかどうか。 |
| `spring.sql.migration.ignore-migration-patterns` | `List<String>` | `*:future` | 無視する履歴の問題。`type:status` の形で: type は `versioned`、`repeatable`、`*`。status は `missing` (適用済みで、ファイルになく、最新のファイルより低い)、`future` (適用済みで、すべてのファイルより新しい)、`ignored` (最新の適用済みのものより低いファイルで、一度も適用されていない)、`*`。デフォルトでは、アプリケーションの後のバージョンのデータベースでも起動できる。 |
| `spring.sql.migration.baseline-on-migrate` | `bool` | `false` | テーブルがあって履歴のないデータベースを、起動を止める代わりに `baseline-version` にあるものとみなすかどうか。 |
| `spring.sql.migration.baseline-version` | `String` | `1` | ベースラインのバージョン。 |
| `spring.sql.migration.baseline-description` | `String` | `<< Baseline >>` | ベースラインの説明。 |
| `spring.sql.migration.placeholders.<name>` | `String` | なし | スクリプト内のプレースホルダー `<name>` の値。 |
| `spring.sql.migration.placeholder-replacement` | `bool` | `true` | スクリプトのプレースホルダーを置き換えるかどうか。 |
| `spring.sql.migration.placeholder-prefix` | `String` | `${` | プレースホルダーの始まり。空であってはならない。 |
| `spring.sql.migration.placeholder-suffix` | `String` | `}` | プレースホルダーの終わり。空であってはならない。 |
| `spring.sql.migration.group` | `bool` | `false` | 保留中のすべてのマイグレーションを、それぞれ独自のものではなく一つのトランザクションで実行するかどうか。 |
| `spring.sql.migration.connect-retries` | `int` | `0` | 起動時に失敗した接続を再試行する回数。 |
| `spring.sql.migration.connect-retries-interval` | `Duration` | `10s` | それらの試行の間の待機。 |
| `spring.sql.migration.lock-timeout` | `Duration` | `1m` | 別のプロセスが保持するマイグレーションのロックを、あきらめるまでランナーが待つ時間。 |

## spring.sql.init: SQL スクリプト

マイグレーションがないときに使われます。[スキーマとマイグレーション](schema.md) を参照してください。

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.sql.init.mode` | `embedded`、`always`、`never` | `embedded` | `schema.sql` と `data.sql` を実行するタイミング: Spring Boot と同じく、`embedded` はメモリ上のデータベース (`sqlite::memory:`) でだけ。`always`。`never`。 |
| `spring.sql.init.schema-locations` | `List<String>` | 空: `resources:schema.sql` と `resources:schema-<platform>.sql`。どちらも任意 | スキーマのスクリプト。指定したロケーションは、`optional:` で始まらない限り存在しなければならない。その中の `@@platform@@` はプラットフォームに置き換えられる。 |
| `spring.sql.init.data-locations` | `List<String>` | 空: `resources:data.sql` と `resources:data-<platform>.sql` | データのスクリプト。 |
| `spring.sql.init.platform` | `String` | `all` | プラットフォームのスクリプトの名前に入るプラットフォーム。 |
| `spring.sql.init.continue-on-error` | `bool` | `false` | 失敗した文を、起動を止める代わりにログに出してスキップするかどうか。 |
| `spring.sql.init.separator` | `String` | `;` | 文の区切り。 |
| `spring.sql.init.encoding` | `String` | `utf-8` | スクリプトファイルのエンコーディング。 |

## spring.data.jdbc: スキーマのモードとロギング

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.data.jdbc.schema` | `none`、`validate`、`create`、`create-drop` | `validate` | スターターがエンティティのスキーマに対して行うこと: 何もしない。テーブルと列が存在し合っていることをチェックする。ないテーブルを作成する。作成してコンテキストが閉じるときに削除する。`create` と `create-drop` は、マイグレーションやスクリプトとともに使うものではない。 |
| `spring.data.jdbc.show-sql` | `bool` | `false` | 文を info でログに出し、デフォルトのレベルで表示されるようにするかどうか (Spring Boot の `spring.jpa.show-sql`)。 |
| `spring.data.jdbc.format-sql` | `bool` | `false` | ログの SQL を複数行にするかどうか。 |
| `spring.data.jdbc.show-parameters` | `bool` | `false` | バインドされた値も trace ではなく info でログに出すかどうか。秘密に見える名前のものはマスクされたまま。 |
| `spring.data.jdbc.slow-query-threshold` | `Duration` | なし | これより遅い文は warn でログに出される。すべてのビルドで。 |
| `spring.main.startup-checks.enabled` | `bool` | 未設定: デバッグビルドとプロファイルビルド | 実行時ではなくジェネレーターが読む。`true` は起動時チェックの `transactionValidator` と `dataFailureAnalyzer` をすべてのビルドに残し、`false` はどのビルドにも残さない。未設定: デバッグビルドとプロファイルビルドだけ。そのため、リリースビルドでは誤った `@Transactional` メソッドは最初の呼び出しで失敗する。 |

`show-sql` もジェネレーターが読みます。プロファイルのない設定で `true` にすると `show-sql`、`format-sql`、`show-parameters` がすべてのビルドに残り、`false` ならどのビルドにも残らず、未設定ならデバッグビルドとプロファイルビルドだけです。`slow-query-threshold` はすべてのビルドに残ります。[SQL のログ](logging.md#リリースビルドでは) を参照してください。

## spring.jdbc.template

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.jdbc.template.query-timeout` | `Duration` | なし | `JdbcTemplate` の Bean の各文を制限する (`500ms` や `10s` など)。超えると `QueryTimeoutException`。 |

## spring.data.store: デフォルトのストア

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.data.store` | `String` | プライマリーのデータソースがあれば `jdbc`、なければ `memory` | `@UseStore` も `@UseDataSource` もないリポジトリのストア。`memory`、`jdbc`、または別のパッケージのストアの名前。どのストアにもない名前は、リポジトリが作成されるときに、存在するストアを示して失敗させる。ビルドも、プロファイルのないファイルからこれを読む。[ストアとその機能](stores.md) を参照。 |

## spring.data.memory: メモリ上のストア

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.data.memory.lock-timeout` | `Duration` | `10s` | メモリ上のストアが行ロックを待つ時間 (`500ms` など)。ゼロは `nowait` と同じく即座に失敗する。 |

## spring.data.web: コントローラーでのページング

`spring_boot_starter_web` も依存関係にある場合にだけ読まれます。[Web アプリケーションで](web.md) を参照してください。

| キー | 型 | デフォルト | 意味 |
|---|---|---|---|
| `spring.data.web.pageable.default-page-size` | `int` | `20` | リクエストに `size` がないときのページサイズ。 |
| `spring.data.web.pageable.max-page-size` | `int` | `2000` | 最大のページサイズ。より大きい `size` はこれに切り詰められる。 |
| `spring.data.web.pageable.one-indexed-parameters` | `bool` | `false` | `page` パラメーターを 0 ではなく 1 から始めるかどうか。 |
| `spring.data.web.pageable.page-parameter` | `String` | `page` | ページ番号のパラメーターの名前。 |
| `spring.data.web.pageable.size-parameter` | `String` | `size` | ページサイズのパラメーターの名前。 |
| `spring.data.web.pageable.prefix` | `String` | `''` | ページとサイズのパラメーター名の前に置くプレフィックス。 |
| `spring.data.web.pageable.qualifier-delimiter` | `String` | `_` | `@Qualifier` とパラメーター名の間の区切り (`x_page`)。 |
| `spring.data.web.sort.sort-parameter` | `String` | `sort` | ソートのパラメーターの名前。 |

## 他のパッケージから読まれるもの

| キー | パッケージ | デフォルト | 意味 |
|---|---|---|---|
| `management.health.db.enabled` | Actuator | `true` | データソースごとに一つのインジケーターを持つ `db` のヘルスコントリビューターを登録するかどうか。 |
| `logging.level.spring.jdbc.core.JdbcTemplate` | ロギング | | `debug` は各文を示す。 |
| `logging.level.spring.jdbc.core.StatementCreatorUtils` | ロギング | | `trace` はバインドされた値を示す。 |
| `logging.level.spring.sql.migration` | ロギング | | マイグレーションのランナーの行。 |

## Spring (Java) との対応

ほとんどのキーは Spring Boot の名前を保っています: `spring.datasource.url`、`username`、`password`、`spring.sql.init.*`、`spring.jdbc.template.query-timeout`、`spring.data.web.*`。違い:

| Spring Boot | ここでは |
|---|---|
| `spring.datasource.hikari.maximum-pool-size` とその他の Hikari のキー | `spring.datasource.pool.*` |
| `spring.flyway.*` | `spring.sql.migration.*` (Spring の名前は起動を止める) |
| `spring.jpa.hibernate.ddl-auto` | `spring.data.jdbc.schema` (`update` はない) |
| `spring.jpa.show-sql` | `spring.data.jdbc.show-sql` |
| コードでの 2 つ目の `DataSource` | `spring.datasources.<name>.*` |

## 関連項目

- [データソース](data-sources.md)
- [スキーマとマイグレーション](schema.md)
- [SQL のロギング](logging.md)
- [@ConfigurationProperties](../spring-core-dart/config/configuration-properties.md)
