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]
相关文章推荐
- PropertyPlaceholderConfigurer的用法(使用spring提供的类读取数据库配置信息.properties)
- spring使用PropertyPlaceholderConfigurer扩展来满足不同环境的参数配置
- Spring配置文件中jdbc:initialize-database标签应用以及PropertyPlaceholderConfigurer配置的应用
- 系统启动PropertyPlaceholderConfigurer加载配置到spring容器中
- Spring PropertyPlaceholderConfigurer Usage - 使用系统变量替换spring配置文件中的变量
- Spring环境搭建之:通过PropertyPlaceholderConfigurer加载属性配置文件:
- spring ApplicationContext.xml之PropertyPlaceholderConfigurer配置数据库
- spring使用多个PropertyPlaceholderConfigurer的配置
- Spring PropertyPlaceholderConfigurer Usage - 使用系统变量替换spring配置文件中的变量
- Spring PropertyPlaceholderConfigurer初始化properties配置文件
- spring中的PropertyPlaceholderConfigurer访问properties文件配置
- spring使用PropertyPlaceholderConfigurer扩展来满足不同环境的参数配置
- Spring配置:用context:property-placeholder替换PropertyPlaceholderConfigurer
- spring 配置文件 获取变量(PropertyPlaceholderConfigurer)
- Spring配置文件中使用PropertyPlaceholderConfigurer配置获取jdbc的配置信息
- Spring配置:用context:property-placeholder替换PropertyPlaceholderConfigurer
- Spring 配置之 PropertyPlaceholderConfigurer
- 动态设置spring配置PropertyPlaceholderConfigurer location的路径
- Spring PropertyPlaceholderConfigurer 自定义扩展来解决多环境配置加载的问题
- 【Spring配置】org.springframework.beans.factory.config.PropertyPlaceholderConfigurer 用法