Spring - " context:property-placeholder" - 财产优先权 [英] Spring - "context:property-placeholder" - property priority

查看:73
本文介绍了Spring - " context:property-placeholder" - 财产优先权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由许多应用程序组成的项目。

我在我的一个应用程序中有这个。

I have a project which consists of many apps.
I have this in one of my apps.

< context:property-placeholder
location =file:/config/p1.properties,file:/config/p2.properties/>

现在,我想在 p2.properties 中定义一个属性,该属性已存在于 p1.properties 。这就是我想在p2中基本覆盖该属性(给它一个不同的值)。这是因为在运行时p1在许多应用程序之间共享,而p2仅由我的应用程序使用。所以我不想影响所有应用程序,只是我的应用程序。

Now, I want to define a property in p2.properties which already exists in p1.properties. That is I want to basically override that property in p2 (give it a different value). This is because at runtime p1 is shared between many apps, and p2 is just used by my app. So I don't want to affect all apps, but just my app.

1)我想知道我将在p2中定义的属性值是否优先。

2)订单是否在<$ c $中c> location
问题如果是这样,第二个

优先于第一个吗?

1) I wonder if the property value which I will define in p2 will take priority.
2) Does the order in location matter and if so, does the second one
take priority over the first one?

推荐答案

您配置 property-placeholder 的方式,任何属性你在 p2.properties 将优先于 p1.properties 中的那些。

The way you have configured the property-placeholder, any property you have in p2.properties will take precedence over the ones in p1.properties.

这是因为最后一个文件中的属性始终优先。

That is because the properties in last file always take precedence.

您设置的是SysAdmins或DevOps人员覆盖的标准方式您的应用程序的属性。例如,您可以将第一个文件作为类路径属性文件,而第二个文件可能就像您拥有它一样,这是一个基于文件系统的属性文件,其值覆盖第一个文件。

What you have setup is a standard way for SysAdmins or DevOps people to override properties of your application. You could for example have the first file be a classpath properties file while the second one could be like you have it, a file systems based properties file, whose values override the ones in the first.

如果你检查 PropertiesLoaderSupport 的noreferrer> JavaDoc (它处理资源的加载,是一个由 PropertySourcesPlaceholderConfigurer扩展的抽象类)你会在 setLocations 方法中看到它有以下注释

If you check the JavaDoc of PropertiesLoaderSupport (which handles the loading of the resources and is an abstract class that is extended by PropertySourcesPlaceholderConfigurer) you will see that in the setLocations method it has the following comment


注意:在重叠键的情况下,在以后的文件中定义的属性将覆盖属性
定义的早期文件。因此,请确保
最具体的文件是给定
位置列表中的最后一个。

Note: Properties defined in later files will override properties defined earlier files, in case of overlapping keys. Hence, make sure that the most specific files are the last ones in the given list of locations.

这篇关于Spring - &quot; context:property-placeholder&quot; - 财产优先权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆