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 重写占位符配置器的更多相关文章

  1. 8 -- 深入使用Spring -- 1...4 属性占位符配置器

    8.1.4 属性占位符配置器 PropertyPlaceholderConfigurer 是一个容器后处理器,负责读取Properties属性文件里的属性值,并将这些属性值设置成Spring配置文件的 ...

  2. spring4笔记----PropertyOverrideConfigureer 重写占位符配置器(图)

  3. spring4笔记----PropertyPlaceholderConfigurer 属性占位符配置器

    driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/spring username=root password= ...

  4. spring占位符解析器---PropertyPlaceholderHelper

    一.PropertyPlaceholderHelper 职责 扮演者占位符解析器的角色,专门用来负责解析路劲中or名字中的占位符的字符,并替换上具体的值 二.例子 public class Prope ...

  5. Spring源码解析之PropertyPlaceholderHelper(占位符解析器)

    Spring源码解析之PropertyPlaceholderHelper(占位符解析器) https://blog.csdn.net/weixin_39471249/article/details/7 ...

  6. 【mybatis源码学习】mybtias基础组件-占位符解析器

    一.占位符解析器源码 1.占位符解析器实现的目标 通过解析字符串中指定前后缀中的字符,并完成相应的功能. 在mybtias中的应用,主要是为了解析Mapper的xml中的sql语句#{}中的内容,识别 ...

  7. Spring - IoC(12): 属性占位符

    使用属性占位符可以将 Spring 配置文件中的部分元数据放在属性文件中设置,这样可以将相似的配置(如 JDBC 的参数配置)放在特定的属性文件中,如果只需要修改这部分配置,则无需修改 Spring ...

  8. Spring import配置文件使用占位符

    import使用占位符 连接池切换导入配置的代码: <import resource="classpath:META-INF/spring/spring-${db.connection ...

  9. Spring与Mybatis整合占位符无法解析问题

    问题:写了一个新的dao接口,进行单元测试时提示: Initialization of bean failed; nested exception is org.springframework.bea ...

随机推荐

  1. android开发(42) 使用andorid操作蓝牙打印机

    最近接到一个需求,使用android发起打印任务,通过蓝牙连接打印机.条件如下: 打印机:南京富士通DPK760E,具有蓝牙功能 Android手机:普通手机,Android 4.4版本,具有蓝牙功能 ...

  2. Android训练课程(Android Training) - 添加活动栏(使用action bar)

    2014-10-28 张云飞VIR 翻译自:https://developer.android.com/training/basics/actionbar/index.html 添加活动栏(Addin ...

  3. sql 字符带下划线匹配问题

    SQL 中 _下划线 作用是 匹配一个任意字符. 如果我们要去掉下划线的作用 单纯只用作一个字符则需要转义成    like '%\_%' escape '\' 字段 1.order_qrsc 2.o ...

  4. 用stringr包处理字符串

    <Machine Learning for Hackers>一书的合著者John Myles White近日接受了一个访谈.在访谈中他提到了自己在R中常用的几个扩展包,其中包括用ggplo ...

  5. (笔记)Linux下怎么安装tar.gz的软件

    一般这种的就是源代码.先下载下来.然后cd到下载目录.用tar xvfz XXX.tar.gz的解压.然后进入解压后的目录. 打./configure生成配置文件.打make对源代码进行编译,生成库和 ...

  6. SpringMVC系列(七)视图解析器和视图

    在springmvc.xml里面配置视图解析器 <!-- 配置视图解析器: 如何把 handler 方法返回值解析为实际的物理视图 --> <bean class="org ...

  7. e824. 获得和设置JSplitPane中的子组件

    // Create a left-right split pane JSplitPane hpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, lef ...

  8. 嵌入式开发之hi3519--- pcie dma和dma cache 缓存更新sync memery

    http://blog.csdn.net/likeping/article/details/42235111 linux下dma 管理 http://blog.csdn.net/skyflying20 ...

  9. Linux 下 CPU 使用率与机器负载的关系与区别

    原文链接:  http://blog.chinaunix.net/uid-28541347-id-4926054.html 当我们使用top命令查看系统的资源使用情况时会看到load average, ...

  10. u3d changeTexs

    using UnityEngine; using System.Collections; using System.Collections.Generic; public class CTex : M ...