PropertyPlaceholderConfigurer可以将xml文件中的属性值放在另一个单独的标准java Properties文件中去。在XML文件中用${key}替换为指定的properties文件中的值。这样的话,只需要对properties文件进行修改,而不用对xml配置文件进行修改。
使用示例
1、PropertyPlaceholderConfigurer配置
<bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- 注意这两种value值的写法 -->
<value>/WEB-INF/mail.properties</value>
<value>classpath: conf/sqlmap/jdbc.properties</value>
</list>
</property>
</bean>
2、xml配置
<bean id="slave1_main" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver">
</property>
<property name="jdbcUrl" value="${datasource.slave1_main.jdbcUrl}"></property>
<property name="user" value="${datasource.slave1_main.user}"></property>
<property name="password" value="${datasource.slave1_main.password}"></property>
</bean>
3、properties配置
datasource.master_main.jdbcUrl=jdbc:mysql://127.0.0.1:3306/uc?characterEncoding=utf8
datasource.master_main.user=root
datasource.master_main.password=
相关推荐
Spring中PropertyPlaceholderConfigurer的使用
Spring属性占位符PropertyPlaceholderConfigurer的使用,自己写的一个demo
NULL 博文链接:https://wokeke.iteye.com/blog/2214113
主要介绍了Spring如何使用PropertyPlaceholderConfigurer读取文件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
6 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 7 8 9 <value>/WEB-INF/jdbc.properties 10 11 12 13 14 它配置了以下功能: 读取...
6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 6.8.1.1. @Configurable object的单元测试 6.8.1.2. 多application context情况下的处理 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来...
第一个 Struts 程式 在 Struts 中整合 Spring 第一个 JSF 程式 在 JSF 中整合 Spring <br> 其它 Spring 提供了简化且一致的方式,让您在使用一些 API 或服务时更加简单。 远程...
NULL 博文链接:https://chyy001.iteye.com/blog/1338488
使用Spring.NET进行面向方面的编程 12.1.简介 12.1.1.AOP基本概念 12.1.2.Spring.NET AOP的功能 12.1.3.Spring.NET的AOP代理 12.2.Spring.NET中的切入点 12.2.1.概念 12.2.2.切入点的操作 12.2.3.Spring.NET提供的...
4.8.2.1 示例:PropertyPlaceholderConfigurer. 82 4.8.2.2 示例:PropertyOverrideConfigurer 83 4.8.3 使用FactoryBean 来自定义实例化逻辑. 84 4.9 基于注解的容器配置. 85 4.9.1 @Required....
#Spring 属性注释扩展的 PropertyPlaceHolderConfigurer 使用注解将配置属性注入到 Spring 组件中。 注意:Spring 3 现在支持使用 @Value 注释的容器的。 该项目仅用于 Spring 2.5.x 支持。 ##入门Spring房产注解...
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面...<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath:proxool.properties ...
spring3.1中文参考文档,南磊翻译,现在有4章,目录如下: 第一部分 Spring framework概述.......................................................................................................................
PropertyPlaceholderConfigurer PropertyResourceConfigurer PropertyValue PropertyValues PropertyValuesEditor PrototypeAspectInstanceFactory PrototypeTargetSource ProxyConfig ProxyFactory ...
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>WEB-INF/jdbc.properties class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-...
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath*:jdbc.properties <!-- 数据源配置,主要用于开发测试...
JDBCTemp+MySQL示例。Spring,PropertyPlaceholderConfigurer,BeanPropertyRowMapper
什么 与通过从属性文件读取其配置来进行自我配置相比,对于应用程序而言,有什么可能更简单? 好吧,对于业务应用程序而言... 首先,我们将使用PropertyPlaceholderConfigurer通过读取存储在.properties文件中的属性来