spring配置文件中context:property-placeholder导入多个独立的配置文件

spring中 context:property-placeholder 导入多个独立的 .properties配置文件?

Spring容器采用反射扫描的发现机制,在探测到Spring容器中有一个 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的 Bean就会停止对剩余PropertyPlaceholderConfigurer的扫描(Spring 3.1已经使用PropertySourcesPlaceholderConfigurer替代 PropertyPlaceholderConfigurer了)。

换句话说,即Spring容器仅允许最多定义一个PropertyPlaceholderConfigurer(或<context:property-placeholder/>),其余的会被Spring忽略掉(其实Spring如果提供一个警告就好了)

举个例子,applicationContext.xml文件中需要导入jdbc.properties和redis.properties两个配置文件,

那这样写是不行的,只能识别到jdbc.properties

<context:property-placeholder location="classpath:jdbc.properties" />
<context:property-placeholder location="classpath:redis.properties" />

咋解决呢?

通配符解决

<context:property-placeholder location="classpath*:conf/conf*.properties"/>

原文地址:https://www.cnblogs.com/shamo89/p/6674095.html