LoginSignup
1
0

More than 3 years have passed since last update.

Spring Bootがアプリケーションの実行環境を判定するロジック

Posted at

目的

Spring Bootの公式ドキュメントを見ていると、 "If your application runs in Cloud Foundry or Heroku" のように、アプリケーションの実行環境を判定している記述があるので、判定方法を調べました

結論

CloudPlatform が環境変数の有無で判定していました。

Spring Boot 2.3.xの場合
https://github.com/spring-projects/spring-boot/blob/2.3.x/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java

  • Cloud Foundry, Heroku, SAP, K8s が検知対象
  • NONEを指定すると特に検知しないことも可能
  • application.propertiesspring.main.cloud-platform を指定すれば、強制的に実行環境を指定可能

でした。

Spring Bootのバージョンによって CloudPlatform の判定内容は異なるので、お使いのバージョンに沿ったソースを参照してみてください。

1
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
1
0