apollo icon indicating copy to clipboard operation
apollo copied to clipboard

spring boot的配置优先级顺序

Open shenhuaxin opened this issue 4 years ago • 6 comments

描述bug apollo配置的优先级高于命令行参数,导致启动脚本中设置的命令行参数失效。

https://github.com/apolloconfig/apollo/issues/1800#issuecomment-465455448

image 这一行代码导致了apollo的优先级是最高的,但是 -D配置的优先级高于apollo的配置,是因为下面的代码。 image 我尝试将apollo的配置优先级降低,添加到命令行参数后面,这样脚本的命令行参数就优先于apollo配置。 image

期望 命令行参数优先级高于apollo配置

shenhuaxin avatar May 21 '22 09:05 shenhuaxin

The apollo-client-config-data uses the Config Data Loader pattern, which should prevent this issue from happening. It uses the PureApolloConfig, which won't read from System Property or System Env.

As for this specific issue, maybe we could add a config to let the user config the order of apollo property source?

nobodyiam avatar May 22 '22 09:05 nobodyiam

现在是 -Dserver.port 不会被 apollo 覆盖,--server.port 会被 apollo 覆盖。是否 apollo 不应该覆盖启动脚本中设置的配置?

shenhuaxin avatar May 22 '22 10:05 shenhuaxin

@shenhuaxin 你描述的应该是正确的行为,目前的实现没有兼容 --args 的场景。

nobodyiam avatar May 22 '22 11:05 nobodyiam

我是从 spring-boot 的 org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor#postProcessEnvironment 中看到了下面的写法。 感觉这种方案可行。。 image

shenhuaxin avatar May 22 '22 11:05 shenhuaxin

I suppose we could add some configs to adjust the property source overriden behavior just like what spring cloud does.

nobodyiam avatar May 23 '22 01:05 nobodyiam

我明白了你的意思了,我会阅读一下这方面的源码,尝试提交一个pr添加这个功能。

shenhuaxin avatar May 23 '22 01:05 shenhuaxin