`

Spring配置之PropertyPlaceholderConfigurer

阅读更多
<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>

引用

PropertyOverrideConfigurer,类似于PropertyPlaceholderConfigurer,但是与后者相比,前者对于bean属性可以有缺省值或者根本没有值。如果起覆盖作用的 Properties文件没有某个bean属性的内容,那么缺省的上下文定义将被使用。
注意:bean 工厂的定义并不会意识到被覆盖,所以仅仅察看XML定义文件并不能立刻明显地知道覆盖配置是否被使用了。在有多个PorpertyOverrideConfigurer对用一个bean属性定义了不同的值的时候,最后一个将取胜(取决于覆盖的机制)。
Properties文件的一行配置应该是如下的格式:
beanName.property=value,其中beanName是需要覆盖的bean的名字,property是需要覆盖的属性名
分享到:
评论

相关推荐

    Spring PropertyPlaceholderConfigurer配置文件加载器集成ZooKeeper来实现远程配置读取

    NULL 博文链接:https://wokeke.iteye.com/blog/2214113

    Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源

    在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面...&lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;value&gt;classpath:proxool.properties ...

    Spring MVC 入门实例

    6 &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; 7 8 9 &lt;value&gt;/WEB-INF/jdbc.properties 10 11 12 13 14 它配置了以下功能: 读取...

    Spring-Reference_zh_CN(Spring中文参考手册)

    6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点实施 ...

    spring.net中文手册在线版

    Spring.NET是一个应用程序框架,其目的是协助开发人员创建企业级的.NET应用程序。它提供了很多方面的功能,比如依赖注入、面向方面编程(AOP)、数据访问抽象及ASP.NET扩展等等。Spring.NET以Java版的Spring框架为...

    Spring + Hibernate + Struts 事务配置小例子(带提示框等小技巧)

    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;value&gt;WEB-INF/jdbc.properties class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-...

    spring-property-annotations:Spring 2.5.x 组件的带注释的配置属性

    #Spring 属性注释扩展的 PropertyPlaceHolderConfigurer 使用注解将配置属性注入到 Spring 组件中。 注意:Spring 3 现在支持使用 @Value 注释的容器的。 该项目仅用于 Spring 2.5.x 支持。 ##入门Spring房产注解...

    Spring 3 Reference中文

    4.8.2.1 示例:PropertyPlaceholderConfigurer. 82 4.8.2.2 示例:PropertyOverrideConfigurer 83 4.8.3 使用FactoryBean 来自定义实例化逻辑. 84 4.9 基于注解的容器配置. 85 4.9.1 @Required....

    spring3.2+strut2+hibernate4

    &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;value&gt;classpath*:jdbc.properties &lt;!-- 数据源配置,主要用于开发测试...

    spring3.1中文参考文档

    spring3.1中文参考文档,南磊翻译,现在有4章,目录如下: 第一部分 Spring framework概述.......................................................................................................................

    ssh框架在application.xml中配置数据源所需jar

    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;value&gt;classpath:/deploy.properties &lt;!-- 配置sessionFactory ...

    SpringEnvironmentsAndProfiles:研究如何使用Spring管理平台特定的属性文件

    与通过从属性文件读取其配置来进行自我配置相比,对于应用程序而言,有什么可能更简单? 好吧,对于业务应用程序而言,事实并非如此简单! 出现的问题如下:0.如何根据执行平台读取不同的属性? 0.如何保护敏感值,...

    SSI框架整合实例

    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;value&gt;classpath:jdbc.properties ${driver}"/&gt; ${url}"/&gt; ${username}"/&gt; ${password}"/&gt; &lt;!-- 配置...

    springmvcmybatis

    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;!-- ${jdbc.driver}" /&gt; ${jdbc.url}" /&gt; ${jdbc.username}" /&gt; ${jdbc.password}" /&gt; 初始化连接大小 ...

Global site tag (gtag.js) - Google Analytics