一、
<context:property-placeholder/>
这个基于命名空间的配置,其实内部就是创建一个PropertyPlaceholderConfigurer Bean。
<context:property-placeholder/>
配置文件中只能存在一个。
二、
PropertiesFactoryBean
是
PropertiesLoaderSupport
直接的实现类, 专门用来管理properties文件的工厂bean,默认是单例的。
PropertyPlaceholderConfigurer
是解决 properties 文件占位符问题的,也实现了
PropertiesLoaderSupport
类。
(1)使用
PropertyPlaceholderConfigurer
时, @Value表达式的用法是
@Value(value="${properties key}")
(2)使用 PropertiesFactoryBean 时,@Value 用法 是
@Value(value="#{configProperties['properties key']}")
spring推荐使用如下方式配置:
<context:property-placeholder location="classpath:spring/jdbc.properties" />