8 -- 深入使用Spring -- 1...4 重写占位符配置器
8.1.5 重写占位符配置器 (PropertyOverrideConfigurer)
PropertyOverrideConfigurer是Spring提供的另一个容器后处理器。PropertyOverrideConfigurer的属性文件指定的信息可以直接覆盖Spring配置文件中的元数据。
使用PropertyOverrideConfigurer的属性文件,每条属性应保持如下格式:beanId.property = value
beanId 是属性占位符试图覆盖的Bean的id,Property是试图覆盖的属性名(对应于调用setter方法)。
XML :
<?xml version="1.0" encoding="UTF-8"?>
<!-- Spring 配置文件的根元素,使用Spring-beans-4.0.xsd语义约束 -->
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
<property name="locations">
<list>
<value>dbconn.properties</value>
<!-- 如果有多个属性文件,依次在下面列出来 -->
<!-- <value>wawa.properties</value> -->
</list>
</property>
</bean> <!-- 对于采用基于XML Schema的配置文件而言,如果导入了context:命名空间,则可采用如下方式来配置该属性占位符 -->
<!-- <context:property-override location="classpath:wawa.properties"/> --> <!-- 定义数据源Bean,使用C3P0数据源实现 -->
<!-- 配置该Bean时没有指定任何信息,但Properties文件里的信息将会直接覆盖该Bean的属性值。 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
</bean> </beans>
Properties :
dataSource.jdbc.driverClassName=com.mysql.jdbc.Driver
dataSource.jdbc.url=jdbc:mysql://localhost:3306/spring
dataSource.jdbc.username=root
dataSource.jdbc.password=system
由于PropertyOverrideConfigurer容器后处理器,Spring容器使用ApplicationContext作为容器时,容器会自动检测容器后处理器,并使用该容器后处理器来处理Spring容器。
beanId必须是容器中真是存在的Bean的id,否则程序将出错。
如果有多个PropertyOverrideConfigurer对同一个Bean属性进行了覆盖,最后一次覆盖将会获胜。
啦啦啦
8 -- 深入使用Spring -- 1...4 重写占位符配置器的更多相关文章
- 8 -- 深入使用Spring -- 1...4 属性占位符配置器
8.1.4 属性占位符配置器 PropertyPlaceholderConfigurer 是一个容器后处理器,负责读取Properties属性文件里的属性值,并将这些属性值设置成Spring配置文件的 ...
- spring4笔记----PropertyOverrideConfigureer 重写占位符配置器(图)
- spring4笔记----PropertyPlaceholderConfigurer 属性占位符配置器
driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/spring username=root password= ...
- spring占位符解析器---PropertyPlaceholderHelper
一.PropertyPlaceholderHelper 职责 扮演者占位符解析器的角色,专门用来负责解析路劲中or名字中的占位符的字符,并替换上具体的值 二.例子 public class Prope ...
- Spring源码解析之PropertyPlaceholderHelper(占位符解析器)
Spring源码解析之PropertyPlaceholderHelper(占位符解析器) https://blog.csdn.net/weixin_39471249/article/details/7 ...
- 【mybatis源码学习】mybtias基础组件-占位符解析器
一.占位符解析器源码 1.占位符解析器实现的目标 通过解析字符串中指定前后缀中的字符,并完成相应的功能. 在mybtias中的应用,主要是为了解析Mapper的xml中的sql语句#{}中的内容,识别 ...
- Spring - IoC(12): 属性占位符
使用属性占位符可以将 Spring 配置文件中的部分元数据放在属性文件中设置,这样可以将相似的配置(如 JDBC 的参数配置)放在特定的属性文件中,如果只需要修改这部分配置,则无需修改 Spring ...
- Spring import配置文件使用占位符
import使用占位符 连接池切换导入配置的代码: <import resource="classpath:META-INF/spring/spring-${db.connection ...
- Spring与Mybatis整合占位符无法解析问题
问题:写了一个新的dao接口,进行单元测试时提示: Initialization of bean failed; nested exception is org.springframework.bea ...
随机推荐
- 基于云端的通用权限管理系统,SAAS服务,基于SAAS的权限管理,基于SAAS的单点登录SSO,企业单点登录,企业系统监控,企业授权认证中心
基于云端的通用权限管理系统 SAAS服务 基于SAAS的权限管理 基于SAAS的单点登录SSO 基于.Net的SSO,单点登录系统,提供SAAS服务 基于Extjs 4.2 的企业信息管理系统 基于E ...
- pdf ppt word office转图片 教学白板
https://zh-cn.libreoffice.org/ http://www.imagemagick.org/script/ 首先用libreoffice将ppt转换为pdf格式,然后再用con ...
- dplyr包
是Hadley Wickham的新作,主要用于数据清洗和整理,该包专注dataframe数据格式,从而大幅提高了数据处理速度,并且提供了与其它数据库的接口:tidyr包的作者是Hadley Wickh ...
- [hadoop读书笔记] 第一章 初识 Hadoop
P3-P4: 目前遇见的问题很简单:硬盘容量不断提升,1TB的已成为主流,然而数据传输速度从1990年的4.4MB/s仅上升到当前约100MB/s 读取一个1TB的硬盘数据需要耗时至少2.5个小时.写 ...
- android 系统广播
Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:00000099 EndFragment:00012731 String ADD_SHORTCUT_ ...
- linux 将终端进行换行
原始 修改 修改方法 vim .bashrc fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debia ...
- 提供openssl -aes-256-cbc兼容加密/解密的简单python函数
原文链接:http://joelinoff.com/blog/?p=885 这里的示例显示了如何使用python以与openssl aes-256-cbc完全兼容的方式加密和解密数据.它是基于我在本网 ...
- java-selenium下载百度图片
package download; import java.io.DataInputStream; import java.io.File; import java.io.FileOutputStre ...
- e612. Moving the Focus to the Next or Previous Focusable Component
The methods to move the focus to the next or to the previous focusable component are Component.trans ...
- com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method
查看了网友们的错误原因, 需要进行实例化的类没有进行实例化,具体没有实例化的类会在错误信息中显示,在错误信息中搜索“Serializable”即可找到将其实现序列化可消除错误. 是在使用Dubbo提供 ...