zoukankan      html  css  js  c++  java
  • 半夜思考之查漏补缺, Spring 中的容器后处理器

    之前学 Spring 的时候 , 还没听过容器后处理器 , 但是一旦写出来 , 就会觉得似曾相识 .

    容器配置器通常用于对 Spring 容器进行处理 , 并且总是在容器实例化任何其他 Bean 之前 , 读取配置文件中的元数据 , 并有可能修改这些数据 .

    Spring 提供了如下几个常用的容器后处理器 :

    • PropertyPlaceholderConfigurer : 属性占位符配置器
    • PropertyOverrideConfigurer : 重写占位符配置器
    • CustomAutowireConfigurer : 自定义自动装配的配置器
    • CustomScopeConfigurer : 自定义作用域的配置器

    1 . 属性占位符配置器

    看到这个 PropertyPlaceholdConfigurer 时 , 我想大多数都会想到这个标签 :

    <context:property-placeholder location="classpath:xx.properties">

    没错 , 这个就是采用了 Scheme 风格之后的 PropertyPlaceholderConfigurer 的简化配置 , 下面还是写一下这个 Bean 后处理器的原始配置 :

    <bean class="org.springframework.bean.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <!-- 以下是配置文件, 如果有多个, 可配置多个 -->
                <value>dbconn.properties</value>
            </list>
        </property>
    </bean>

    2 . 重写占位符配置器

    重写占位符配置器的作用 :

    按照第一个 , 这个重写占位符配置器也应该有 Scheme 形式的简化版 :

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    1

  • 相关阅读:
    ‘Host’ is not allowed to connect to this mysql server
    centos7安装mysql
    further configuration avilable 不见了
    Dynamic Web Module 3.0 requires Java 1.6 or newer
    hadoop启动 datanode的live node为0
    ssh远程访问失败 Centos7
    Linux 下的各种环境安装
    Centos7 安装 python2.7
    安装scala
    Centos7 安装 jdk 1.8
  • 原文地址:https://www.cnblogs.com/daimajun/p/7297459.html
Copyright © 2011-2022 走看看