一、<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" />
本文介绍了Spring框架中两种主要的属性配置方式:PropertyPlaceholderConfigurer和PropertiesFactoryBean。详细解释了它们的作用及@Value注解的不同用法,并给出了推荐的配置方式。
1953

被折叠的 条评论
为什么被折叠?



