复制别人的文章,本身也试了一下,确实有效,也有点收获,记录一下spring
<context:property-placeholder>
标签提供了一种优雅的外在化参数配置的方式,不过该标签在Spring配置文件中只能存在一份code
当Spring探测到容器中有一个org.springframework.beans.factory.config.PropertyPlaceholderCVonfigurer的Bean就会中止对剩余PropertyPlaceholderConfigurer的扫描,string
即只能存在一个实例io
同个模块中若是出现多个context:property-placeholder ,location properties文件后,运行时出现Could not resolve placeholder 'key' in string value${key1}。容器
缘由是在加载第一个context:property-placeholder时会扫描全部的bean,配置
而有的bean里面出现第二个 context:property-placeholder引入的properties的占位符${key2},方法
但此时尚未加载第二个property-placeholder,因此解析不了${key2}。配置文件
解决办法一,能够将经过模块的多个property-placeholder合并为一个,将初始化放在一块儿。文件
方法二,添加ignore-unresolvable="true",这样能够在加载第一个property-placeholder时出现解析不了的占位符进行忽略掉。标签