PreferencesPlaceHolderConfigurer与Proper tiesFactoryBean与context:property-placeholder区别

一、<context:property-placeholder/>这个基于命名空间的配置,其实内部就是创建一个PropertyPlaceholderConfigurer Bean。<context:property-placeholder/>配置文件中只能存在一个。
二、PropertiesFactoryBeanPropertiesLoaderSupport 直接的实现类, 专门用来管理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" />  

版权声明:本文为addisonjing原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。