背景:
有2个配置文件内容格式一样.
文件1:login.acctID=xxxxxxx login.username=aaaaaa login.password=bbbbbb login.lcid=eee
文件2:
login.acctID=xxxxxxx login.username=cccccc login.password=dddddd login.lcid=fff
然后在 SpringBoot 中2个类用 @PropertySource
来获取属性值. 导致2个类获取到的值都是一样的.
然后度娘搜了半天没搜到, Google搜了下, 第一个就是…
原因是多个 properties
中, 同样的 key
值,最后一个处理的 @PropertySource
会覆盖前面的.
You can’t. The two property sources will be merged into the same Spring Environment. The last declared value for the same key in the your .properties files will override any previous value for the same key. If your read the JavaDoc of @PropertySource you will find the following statement:
In cases where a given property key exists in more than one .properties file, the last @PropertySource annotation processed will ‘win’ and override.