特定环境的spring yml文件 [英] spring yml file for specific environment
问题描述
我有 3 个 yml
文件,即
I have 3 yml
files namely
application-default.yml
-> 默认属性,应该可用在所有个人资料中application-dev.yml
-> 仅针对 dev 的属性个人资料application-prod.yml
-> 仅适用于 prod 配置文件的属性
application-default.yml
-> default properties, should be available in all profilesapplication-dev.yml
-> properties only for dev profileapplication-prod.yml
-> properties only for prod profile
当我通过传递 -Dspring.profiles.active=dev
启动我的启动应用程序时,我能够访问 application-dev.yml
特定属性.但是我无法获得 application-default.yml
文件中定义的属性.以下是我的 application-dev.yml
文件:
When I start my boot application by passing the -Dspring.profiles.active=dev
,I am able to access the application-dev.yml
specific properties.
But I cant get the properties defined in the application-default.yml
files.
Following is my application-dev.yml
file:
Spring:
profiles:
include: default
spring.profiles: dev
prop:
key:value
推荐答案
我能够解决我的问题,这就是我所做的.
I was able to solve my problem, here is what I did.
创建一个文件application-common.yml,把公共属性放在那里.然后在 application-{env}.yml 文件中我把它放在最上面.
Created a file application-common.yml, put the common properties there. Then in the application-{env}.yml files I put this on the top.
spring:
profiles:
include: default
因为我不需要专门加载默认配置文件,这对我有用!!!
Since I dont need to ever load the default profile specifically, this works for me!!!
这篇关于特定环境的spring yml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!