当前位置: 代码迷 >> 综合 >> applicationContext.xml里org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
  详细解决方案

applicationContext.xml里org.springframework.beans.factory.config.PropertyPlaceholderConfigurer

热度:6   发布时间:2023-11-08 01:15:26.0

1.先贴代码

<!--propertyConfigurer --><bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:jdbc.properties</value></list></property></bean>

2.解释

PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是 BeanFactoryPostProcessor接口的一个实现。PropertyPlaceholderConfigurer可以将上下文(配置文 件)中的属性值放在另一个单独的标准java Properties文件中去。在XML文件中用${key}替换指定的properties文件中的值。这样的话,只需要对properties文件进 行修改,而不用对xml配置文件进行修改。

3.升级

为简化PropertyPlaceholderConfigurer的使用,Spring提供了<context:property-placeholder/>元素。下面给出了配置示例,启用它后,开发者便不用配置PropertyPlaceholderConfigurer对象了。

<context:property-placeholder location="userinfo.properties"/> 

 

  相关解决方案