0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Springのプロパティ読み込み順序まとめ(内包 vs 外付け)

Posted at

1. 背景

Springアプリケーションでは、プロパティファイルを複数の場所に配置することができます。

  • JAR 内(classpath)
  • 外付けファイル(./config など)

読み込み順序と優先度を正しく理解することは、設定値が期待通りに反映されるために重要です。


2. XMLでの読み込み(PropertySourcesPlaceholderConfigurer)

<context:property-placeholder
    location="classpath:com/something/jdbc.properties, file:./config/external.properties"
    ignore-unresolvable="true"/>

挙動

  • 読み込み順序: classpath(JAR内) → file(外付け)
  • 優先度: 後から読み込まれたファイルの値が上書きされるため、外付けが優先される
  • 存在しないプロパティ: jar外 や Java システムプロパティで補完される

2. Spring Boot 自動読み込み

  • Spring Boot の application.properties / application.yml 自動ロードでは、外付けファイルが優先される
  • 読み込み順序は自動的に設定されており、XML のように明示的に順序制御はできない

4. まとめ

観点 XML / Java Config Spring Boot 自動ロード
読み込み順序 内包 → 外付け(指定順) 外付け → 内包(自動)
優先される値 後に読み込まれたファイルが上書き 後に読み込まれた値が上書き(外付け優先)

💡 ポイント

  • 読み込み順序と優先度は別物
  • XML では順序を制御可能
  • Spring Boot 自動ロードでは外付け優先がデフォルト
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?