spring中使用外部属性文件
2017-12-30 23:13
239 查看
通过PropertyPlaceholderConfigurer引入属性文件
<!--引入jdbc.propertys--> <bean class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="classpath:com/start/placeholder/jdbc.properties" p:fileEncoding="utf-8"/> <bean id = "database" class = "org.apache.common.dbcp.BasicDataSoucr" destroy-method="close" p:driverClassName="${driverClassName}" p:url = "${url}" p:username = "${username}"/>
通过PropertyPlaceholderConfiguer的location属性引入属性文件,这样,在定义bean的时候就可以引用属性文件中的属性了。
PropertyPlaceholderConfiguer的其他属性
locations可以指定多个属性文件fileEncoding:属性文件的编码方式
order:如果在spring中定义了多个PropertyPlaceholderConfiguer,则通过该属性指定优先顺序。
placeHolderPrefix:”${“,默认的属性占位符
placeHolderSuffix:”$}”,默认的属性占位符
使用< context:property-placeholder > 引用属性文件
<context:property-placeholder location="classpath:com/start/placeholder/jdbc.properties"/>
如果对属性进行加减密
需要继承PropertyPalceholderConfiguer/** *覆盖此方法,可以对属性文件中的所有值进行转换处理 */ void convertProperties(Properties props); /** *在加载属性文件,并读取属性文件中的每一个属性值时都会调用此方法,进行转换处理。 */ void convertProperty(String propName,String properValue); /** *和上一个方法类似,只是没有传入属性名 */ void convertPropertyValue(String properValue);
相关文章推荐
- Spring基础—— 在 Spring Config 中使用外部属性文件
- Spring4深入理解IOC&DI02----Bean配置--自动装配、bean之间的继承与依赖、使用外部属性文件
- spring_scope作用域和使用外部属性文件和spEL表达式
- Spring使用外部属性文件以及常见错误(内附大量图片,很有借鉴意义)
- Spring 中如何使用外部属性文件
- spring ioc之使用外部属性文件
- Spring学习笔记之使用外部属性文件
- Spring_8_使用外部属性文件
- Spring学习记录(六)---使用外部属性文件
- Spring 使用外部属性文件(连接数据库)
- Spring4 学习系列之——使用外部属性文件
- spring中使用外部属性文件(关于PropertyPlaceholderConfigurer)
- Spring学习历程---使用外部属性文件
- spring 使用外部属性文件
- spring(9) Spring中使用外部属性文件
- Spring IOC使用外部属性文件
- spring4学习:使用外部属性文件
- 在Spring中如何使用加密外部属性文件
- Spring_使用外部属性文件
- Spring-7:使用外部属性文件