【spring】 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
2016-12-23 21:12
363 查看
原文链接
可以将上下文(配置文件)中的属性值放在另一个单独的标准java Properties文件中去。在XML文件中用${key}替换指定的properties文件中的值。这样的话,只需要对properties文件进行修改,而不用对xml配置文件进行修改。
从上图中,我们看到PropertyPlaceholderConfigurer实现了三个bean生命周期的接口:BeanFactoryAware & BeanNameAware & BeanFactoryPostProcessor。关于spring bean的生命周期,可以参考这里http://blog.csdn.net/gjb724332682/article/details/46767463。
PropertyResourceConfigurer.postProcessBeanFactory()将properties文件中的属性进行merge,convert,最后调用PropertyPlaceholderConfigurer.processProperties()完成遍历bean定义替换属性占位符。
例子:
可以将上下文(配置文件)中的属性值放在另一个单独的标准java Properties文件中去。在XML文件中用${key}替换指定的properties文件中的值。这样的话,只需要对properties文件进行修改,而不用对xml配置文件进行修改。
从上图中,我们看到PropertyPlaceholderConfigurer实现了三个bean生命周期的接口:BeanFactoryAware & BeanNameAware & BeanFactoryPostProcessor。关于spring bean的生命周期,可以参考这里http://blog.csdn.net/gjb724332682/article/details/46767463。
PropertyResourceConfigurer.postProcessBeanFactory()将properties文件中的属性进行merge,convert,最后调用PropertyPlaceholderConfigurer.processProperties()完成遍历bean定义替换属性占位符。
例子:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>WEB-INF/conf/xx.properties</value> </property> <property name="fileEncoding"> <value>UTF-8</value> </property> </bean> <!--当然也可以引入多个属性文件,如: --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>/WEB-INF/mail.properties</value> <value>classpath:conf/sqlmap/jdbc.properties</value> </list> </property> </bean>
相关文章推荐
- 【Spring配置】org.springframework.beans.factory.config.PropertyPlaceholderConfigurer 用法
- org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
- spring 和mybatis整合时 使用context:property-placeholder载不进属性 还报org.springframework.beans.factory.BeanCrea
- org.springframework.beans.factory.config.CustomEditorConfigurer
- org.springframework.beans.factory.config.MethodInvokingFactoryBean的使用
- org.springframework.beans.factory.config.PropertiesFactoryBean
- Could not load org/springframework/beans/factory/config/Scope.class. java.util.zip.ZipException: inv
- 解决 java.lang.ClassNotFoundException: org.springframework.beans.factory.config.EmbeddedValueResolver
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named "" must be of type [org.apache.struts.action.Action
- org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException
- ssh2 整合 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in Servl
- 题目:org.springframework.beans.factory.BeanCreationException(hibernate中的jar包和spring中的jar包冲突)异常产生的原因和解决方案。
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException的问题所在!!
- nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Can
- 异常:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletCo
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'selectcommoninfo' defined in ServletCont
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContex
- org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from class path resource