Profile Inheritage In spring boot

gka*_*ura 4 java spring-profiles spring-boot

是否可以在 spring boot 中拥有一个配置文件以及另一个继承大多数父值和 bean 的配置文件?

例如,我有两个配置文件 staging 和 staging-task。我希望 staging-task 继承 staging 配置文件的数据库配置,但是我希望它覆盖 jpa 配置。

配置文件继承是否可用于@Configuration bean。

JRR*_*JRR 7

是的。弹簧靴中可能有弹簧轮廓。对于您的问题,请将您的常用数据库配置放在 application.yml(默认配置文件)中。

您可以覆盖 application-stage.yml 中的其他属性。

当活动配置文件为stage时,Spring 将从 application.yml 读取属性并从 application-stage.yml 覆盖。

  • 超过一级继承又如何呢?例如 foo-dev、foo-prod 继承自 foo 和 bar-dev、bar-prod 继承自 bar (2认同)