PropertiesFactoryBean PropertyPlaceholderConfigurer 区别
来源:互联网 发布:淘宝网页版回收站 编辑:程序博客网 时间:2024/06/07 17:12
正如 stackoverflow 上说的,PropertiesFactoryBean 是PropertiesLoaderSupport 直接的实现类, 专门用来管理properties文件的工厂bean,默认是单例的,
而 PropertyPlaceholderConfigurer 是 解决 properties 文件占位符问题的,也实现了 PropertiesLoaderSupport 类。
在java 代码里,一般是使用@Value注解来引用 properties 文件的属性。
使用 PropertyPlaceholderConfigurer 时, @Value表达式的用法是 @Value(value="${properties key}") ,
使用 PropertiesFactoryBean 时,我们还可以用@Value 读取 properties对象的值, @Value 用法 是 @Value(value="#{configProperties['properties key']}")
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:/config/jdbc.properties</value> <value>classpath:/config/base.properties</value> </list> </property> </bean> <!-- 属性文件读入 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="properties" ref="configProperties" /> </bean>
@Value(value="${profit.rate.csProfitRate}")double rate = 0.9; @Value(value="#{configProperties['profit.rate.csProfitRate']}")double rate2 = 0.9;
最后 rate 和rate2 值是一样的。
参考资料:
1、 http://stackoverflow.com/questions/20353999/propertiesfactorybean-vs-propertyplaceholderconfigurer-spring
2、 使用spring注解方法读取properties文件中值
3、Spring的@PropertySource和@Value注解例子
4、 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-typesafe-configuration-properties
5 、 http://outofmemory.cn/code-snippet/3700/spring-bean-property-inject
- PropertiesFactoryBean PropertyPlaceholderConfigurer 区别
- PropertiesFactoryBean PropertyPlaceholderConfigurer 区别
- propertiesfactorybean vs propertyplaceholderconfigurer spring?
- propertiesfactorybean vs propertyplaceholderconfigurer spring?
- spring管理属性配置文件properties——PropertiesFactoryBean和PropertyPlaceholderConfigurer的区别
- Spring读取properties:PropertiesFactoryBean和PropertyPlaceholderConfigurer
- spring学习的点点滴滴——PropertyPlaceholderConfigurer,PropertiesFactoryBean
- PropertyPlaceholderConfigurer和ReloadableResourceBundleMessageSource区别
- PropertyPlaceholderConfigurer
- PropertyPlaceholderConfigurer
- PropertyPlaceholderConfigurer
- propertyplaceholderconfigurer
- PropertyPlaceholderConfigurer
- PropertyPlaceholderConfigurer
- PropertyPlaceholderConfigurer
- PropertyPlaceholderConfigurer
- PropertiesFactoryBean的使用
- Spring--PropertyPlaceholderConfigurer
- 权限系统设计思考
- 221. Maximal Square
- requireJs 初探
- gdb调试时打印寄存器的不同类型值
- JDK和两个JRE
- PropertiesFactoryBean PropertyPlaceholderConfigurer 区别
- 最快最简单的排序算法:桶排序
- propertiesfactorybean vs propertyplaceholderconfigurer spring?
- 冒泡排序
- Spring中配置和读取多个Properties文件
- 快速排序
- Spring通过@Value注解注入属性的几种方式
- 论文笔记 | VERY DEEP CONVOLUTIONAL NETWORKS FOR LARGE -SCALE IMAGE RECOGNITION
- newbie: <lists> versus <util:list>