Spring中的xml中使用<context:property-placeholderlocation>标签导入配置文件时,想要导入多个properties配置文件,以下:java
<context:property-placeholderlocation="classpath:a.properties " /> <context:property-placeholderlocation="classpath:b.properties " />
结果发现不行,第二个配置文件始终读取不到,后来发现<context:property-placeholder>
标签在Spring配置文件中只能存在一份!!!Spring容器是采用反射扫描的发现机制,经过标签的命名空间实例化实例,当Spring探测到容器中有个org.springframework.beans.factory.config.PropertyPlaceholderCVonfigurer的Bean就会中止对剩余PropertyPlaceholderConfigurer的扫描,即只能存在一个实例。spring
<context:property-placeholder location="" file-encoding="" ignore-resource-not-found="" ignore-unresolvable="" properties-ref="" local-override="" system-properties-mode="" order="" />
那若是有多个配置文件怎么办呢?那就多个文件之间以“,”分隔,以下:ide
<context:property-placeholderlocation="classpath:a.properties,classpath:b.properties" />
值得注意的是:多个配置文件将依次加载,若是后一个文件中有和前面某一个文件中属性名是相同的,最终取的值是后加载的值。spa
javaconfig的加载在xml文件以前,故在javaconfig配置的会被xml中配置的实例覆盖code