[英]“dev” config overrides “test” config in Quarkus
In my Quarkus application, I don't want passwords to be versionned by Git.在我的 Quarkus 应用程序中,我不希望 Git 对密码进行版本控制。
I don't have any issue with the prod
profile because I have a config file in $PWD/config/application.properties
.我对
prod
配置文件没有任何问题,因为我在$PWD/config/application.properties
中有一个配置文件。 Fine.美好的。
For the dev
profile, I'm using the .env
approach which contains properties such as:对于
dev
配置文件,我使用.env
方法,其中包含以下属性:
QUARKUS_DATASOURCE_PASSWORD=foo
I'm trying to setup tests and I need some separate conf for tests.我正在尝试设置测试,我需要一些单独的 conf 进行测试。 So I have the following config in my
src/test/resources/application.properties
:所以我在
src/test/resources/application.properties
中有以下配置:
%test.quarkus.datasource.password=bar
Unfortunately, the test value ( bar
) is overriden by the .env
value ( foo
) which is supposed to be dedicated to the dev
profile.不幸的是,测试值(
bar
)被.env
值( foo
)覆盖,该值应该专用于dev
配置文件。
I don't find an elegant way to fix it.我没有找到一种优雅的方法来解决它。
Based on https://quarkus.io/guides/config#overriding-properties-at-runtime I have 5 possible approachs:基于https://quarkus.io/guides/config#overriding-properties-at-runtime我有 5 种可能的方法:
.env
file: Could work, but I can't specifiy value for dev
profile only (aka %dev.[...]
); .env
文件:可以工作,但我不能只为dev
配置文件指定值(又名%dev.[...]
);$PWD/config/application.properties
file: well, this is for dev mode, I don't find it convinient as target is cleared and I have to copy again the config
folder after each mvn clean
; $PWD/config/application.properties
文件:嗯,这是用于开发模式的,我觉得它不方便,因为目标已被清除,我必须在每次mvn clean
之后再次复制config
文件夹;ConfigSource
or ConfigSourceProvider
.ConfigSource
或ConfigSourceProvider
。 I know this one could work, but I prefer to avoid doing specific stuff in my project, and stay with the builtin Quarkus config.I just found that I was wrong about that:我刚刚发现我错了:
.env
file: Could work, but I can't specifiy value for dev profile only (aka%dev.[...]
);.env
文件:可以工作,但我不能只为开发配置文件指定值(又名%dev.[...]
);
It is possible to have custom profile values in .env
file: .env
文件中可以有自定义配置文件值:
_DEV_QUARKUS_DATASOURCE_PASSWORD=foo
As I can prefix the property with _DEV_[...]
, this value is for dev
profile only: the test
property is not overriden anymore.因为我可以在属性前面加上
_DEV_[...]
,所以这个值仅适用于dev
配置文件: test
属性不再被覆盖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.