spring中PropertyPlaceholderConfigurer的使用,引入外部资源文件
2017-08-21 13:58
501 查看
PropertyPlaceholderConfigurer的使用
在开发web端应用时,我们一般都是把数据库那部分资源写在一个***.properties文件中,然后在application中通过${}获取相应的值。
1.db.properties
在开发web端应用时,我们一般都是把数据库那部分资源写在一个***.properties文件中,然后在application中通过${}获取相应的值。
1.db.properties
db.driver=com.mysql.jdbc.Driver db.url=jdbc:mysql://localhost:3306/study?characterEncoding=UTF-8&useUnicode=true db.username=root db.password=root2.applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-lazy-init="false"> <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:db.properties</value> </list> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>${db.driver}</value> </property> <property name="url"> <value>${db.url}</value> </property> <property name="username"> <va 4000 lue>${db.username}</value> </property> <property name="password"> <value>${db.password}</value> </property> </bean>
相关文章推荐
- spring中使用外部属性文件(关于PropertyPlaceholderConfigurer)
- Spring配置文件中使用PropertyPlaceholderConfigurer配置获取jdbc的配置信息
- spring管理属性配置文件properties——使用PropertyPlaceholderConfigurer
- 使用外部属性文件(关于PropertyPlaceholderConfigurer)
- Spring 后置处理器 PropertyPlaceholderConfigurer 类(引用外部文件)
- 【转】spring管理属性配置文件properties——使用PropertiesFactoryBean|spring管理属性配置文件properties——使用PropertyPlaceholderConfigurer
- Spring学习笔记 通过PropertyPlaceholderConfigurer来使用properties文件初始化Map类型属性
- Spring PropertyPlaceholderConfigurer Usage - 使用系统变量替换spring配置文件中的变量
- Spring中使用 PropertyPlaceholderConfigurer 替换xml配置文件中的Bean配置项
- Spring PropertyPlaceholderConfigurer Usage - 使用系统变量替换spring配置文件中的变量
- Spring PropertyPlaceholderConfigurer Usage - 使用系统变量替换spring配置文件中的变量
- Spring PropertyPlaceholderConfigurer的使用
- spring通过.PropertyPlaceholderConfigurer读取配置文件
- Spring中PropertyPlaceholderConfigurer的使用(二)
- Spring中PropertyPlaceholderConfigurer的使用
- spring里PropertyPlaceholderConfigurer读取属性文件
- 配置环境spring使用PropertyPlaceholderConfigurer扩展来满足不同环境的参数配置
- spring使用PropertyPlaceholderConfigurer扩展来满足不同环境的参数配置
- Spring PropertyPlaceholderConfigurer的使用
- 在 Spring.NET 中使用 PropertyPlaceholderConfigurer 设置配置参数