Spring使用context:property-placeholder导入多个路径下properties文件


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

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


同时写两个<context:property-placeholder>标签在Spring配置文件中不行,只能存在一个,Spring通过反射扫描标签的命名实例化Bean。
org.springframework.beans.factory.config.PropertyPlaceholderCVonfigurer只能存在一个实例。

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


如果有相同属性名,多个文件只会取最后读取的一个


classpath和classpath*区别:

classpath:只会到你的class路径中查找找文件。

classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找。

注意: 用classpath*:需要遍历所有的classpath,所以加载速度是很慢的;因此,在规划的时候,应该尽可能规划好资源文件所在的路径,尽量避免使用classpath*。

classpath*的使用:

当项目中有多个classpath路径,并同时加载多个classpath路径下(此种情况多数不会遇到)的文件,*就发挥了作用,如果不加*,则表示仅仅加载第一个classpath路径。

猜你喜欢

转载自blog.csdn.net/lin252552/article/details/84373721