您的位置:首页 > 编程语言 > Java开发

Spring配置之PropertyPlaceholderConfigurer

2010-12-25 19:51 85 查看

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/reportConfig.properties</value>
</property>
<property name="fileEncoding" value="utf-8"/>
</bean>


1.<bean id="configBean" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
2. <property name="locations">
3. <list>
4. <value>classpath*:properties1.properties</value>
5. <value>properties2.properties</value>
6. <value>properties3.properties</value>
7. </list>
8. </property>
9.</bean>


<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:c:/reportConfig.properties</value>
</property>
<property name="fileEncoding" value="utf-8"/>
</bean>


<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<bean class="java.lang.System" factory-method="getenv">
<constructor-arg value="CIRC_REPORT"/>
</bean>
</property>
<property name="fileEncoding" value="utf-8"/>
</bean>


<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name=”ignoreResourceNotFound” value=”true”/>
<property name="location">
<value>${CIRC_REPORT}</value>
</property>
<property name="fileEncoding" value="utf-8"/>
</bean>


[color=green] PropertyOverrideConfigurer,类似于PropertyPlaceholderConfigurer,但是与后者相比,前者对于bean属性可以有缺省值或者根本没有值。如果起覆盖作用的 Properties文件没有某个bean属性的内容,那么缺省的上下文定义将被使用。
注意:bean 工厂的定义并不会意识到被覆盖,所以仅仅察看XML定义文件并不能立刻明显地知道覆盖配置是否被使用了。在有多个PorpertyOverrideConfigurer对用一个bean属性定义了不同的值的时候,最后一个将取胜(取决于覆盖的机制)。
Properties文件的一行配置应该是如下的格式:
beanName.property=value,其中beanName是需要覆盖的bean的名字,property是需要覆盖的属性名 [/color]
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐