PropertyPlaceholderConfigurer将属性文件中的信息加载到XML配置文件中
<!-- 属性文件读入 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:config/jdbc.properties</value>
</list>
</property>
</bean>
<!-- 数据源定义,使用Apache DBCP 连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
jdbc.properties文件:
jdbc.url=jdbc\:mysql\://127.0.0.1\:3306/eop?useUnicode\=true&characterEncoding\=utf8
jdbc.username=root
jdbc.password=root
jdbc.driverClassName=com.mysql.jdbc.Driver
tomcat启动时,配置文件中的信息就加载到XML中了。
分享到:
相关推荐
主要介绍了Spring如何使用PropertyPlaceholderConfigurer读取文件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Spring属性占位符PropertyPlaceholderConfigurer的使用,自己写的一个demo
Spring中PropertyPlaceholderConfigurer的使用
NULL 博文链接:https://wokeke.iteye.com/blog/2214113
与通过从属性文件读取其配置来进行自我配置相比,对于应用程序而言,有什么可能更简单? 好吧,对于业务应用程序而言,事实并非如此简单! 出现的问题如下:0.如何根据执行平台读取不同的属性? 0.如何保护敏感值,...
--读取properties资源文件配置,如deploy.properties--> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath:/deploy.properties <!--...
#Spring 属性注释扩展的 PropertyPlaceHolderConfigurer 使用注解将配置属性注入到 Spring 组件中。 注意:Spring 3 现在支持使用 @Value 注释的容器的。 该项目仅用于 Spring 2.5.x 支持。 ##入门Spring房产注解...
6.4.2. Spring AOP中使用@AspectJ还是XML? 6.5. 混合切面类型 6.6. 代理机制 6.7. 编程方式创建@AspectJ代理 6.8. 在Spring应用中使用AspectJ 6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 6.8.1.1....
使用对象或类的属性值进行注入 4.3.5.2.使用字段值进行注入 4.3.5.3.使用方法的返回值进行注入 4.3.6.IFactoryObject接口的其它实现 4.3.6.1.Log4Net 4.3.7.使用depends-on 4.3.8.自动装配协作对象 4.3.9.检查依赖项...
读取 /WEB-INF/jdbc.properties 文件. 你可以在 list 标签中配置多个 value 标签. database.xml: 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" ...
NULL 博文链接:https://chyy001.iteye.com/blog/1338488
4.4.2.7 使用c-命名空间的XML 快捷方式. 53 4.4.2.8 复合属性名称.. 54 4.4.3 使用depends-on 54 4.4.4 延迟初始化bean . 55 4.4.5 自动装配协作者.. 55 4.4.5.1 自动装配的限制和缺点.. ...
--将action内容放在package元素下,package元素的name值与extends值可以使用默认值,如下所示 --> <interceptors> <interceptor name="authority" class="com.sbz.application.common.LoginIntercepter" /> ...
将:red5-web.xml名修改为myApp-web.xml,内容修改为 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> ...
不使用XML定义档进行 Bean设置 Aware 相关介面 BeanPostProcessor BeanFactoryPostProcessor PropertyPlaceholderConfigurer PropertyOverrideConfigurer CustomEditorConfigurer ...
JDBCTemp+MySQL示例。Spring,PropertyPlaceholderConfigurer,BeanPropertyRowMapper
<?xml version="1.0" encoding="UTF-8"?> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context=...
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。 如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍, bonecp.properties文件: ...
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath:jdbc.properties ${driver}"/> ${url}"/> ${username}"/> ${password}"/> <!-- 配置...