什么是具有多个位置的Spring属性占位符配置器中的属性解析顺序? [英] What is property resolution order in Spring property placeholder configurer with multiple locations?

查看:110
本文介绍了什么是具有多个位置的Spring属性占位符配置器中的属性解析顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个配置:

    <bean id="batchJobProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>first.properties</value>
            <value>second.properties</value>
        </list>
    </property>
</bean>



first.properties具有属性my.url = first.url
second.properties具有属性my.url = second.url

first.properties has property "my.url=first.url" second.properties has property "my.url=second.url"

所以哪个值将被注入myUrlbean?是否有任何已定义的属性解析顺序?

So which value will be injected to the "myUrl" bean? Is there is any defined order of properties resolution?

推荐答案

PropertiesLoaderSupport.setLocation 状态


设置要加载的属性文件的位置。

Set locations of properties files to be loaded.

可以指向经典属性文件或遵循JDK 1.5属性XML格式的XML文件。

Can point to classic properties files or to XML files that follow JDK 1.5's properties XML format.

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

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.

所以my.url的值在second.properties中将覆盖first.properties中my.url的值。

So the value of my.url in second.properties will override the value of my.url in first.properties.

这篇关于什么是具有多个位置的Spring属性占位符配置器中的属性解析顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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