[英]Spring boot profile not picking the properties file
我有application-database.yml
, application-sql.yml
。尝试使用-Dspring.profiles.active=local
运行,但属性数据没有拾取。 如何运行这个?
应用程序-local.yml
spring:
profiles:
group:
local: database, sql, message
application:
name: HP-FETCHER-CONFIG-SERVICE
通过Dspring.profiles.active=local
您告诉 spring 您使用local
配置文件,请改用Dspring.profiles.active=database
我不确定这是否适用于您的项目:
只需使用 application.yml,然后:
spring:
profiles:
active: local, database, sql
---
spring:
profiles: local1
...
...
---
spring:
profiles: local
...
...
---
spring:
profiles: sql
...
...
---
spring:
profiles: database
...
...
当没有-Dspring.profiles.active
启动时,它将使用local, database, sql
。 如果以-Dspring.profiles.active=local1,database,sql
,它将使用local1, database, sql
如果要使用group
,则必须在application.yml
或application.properties
文件中指定它。 相应的博客文章说:
要定义组,您可以在 application.properties 或 application.yml 文件中使用 spring.profiles.group 属性。
对我来说,这似乎按预期工作。 我有以下application.yml
文件
spring:
profiles:
group:
super-1-2: profile-1, profile-2
super-2-3: profile-2, profile-3
---
spring:
config:
activate:
on-profile:
- profile-1
---
spring:
config:
activate:
on-profile:
- profile-2
---
spring:
config:
activate:
on-profile:
- profile-3
如果我在激活配置文件super-1-2
的情况下运行我的应用程序,我会在日志中确认所有三个super-1-2
、 profile-1
和profile-2
都处于活动状态。
2022-08-31 16:52:27.109 INFO 67935 --- [ restartedMain] c.s.n.SampleApplication : The following 3 profiles are active: "super-1-2", "profile-1", "profile-2"
另一方面,如果我在激活配置文件super-2-3
的情况下运行我的应用程序,我会在日志中确认所有三个super-2-3
、 profile-2
和profile-3
都处于活动状态。
2022-08-31 16:52:41.117 INFO 68090 --- [ restartedMain] c.s.n.SampleApplication : The following 3 profiles are active: "super-2-3", "profile-2", "profile-3"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.