以前学 Spring 的时候 , 还没听过容器后处理器 , 可是一旦写出来 , 就会以为似曾相识 . spring
容器配置器一般用于对 Spring 容器进行处理 , 而且老是在容器实例化任何其余 Bean 以前 , 读取配置文件中的元数据 , 并有可能修改这些数据 . ide
Spring 提供了以下几个经常使用的容器后处理器 : spa
- PropertyPlaceholderConfigurer : 属性占位符配置器
- PropertyOverrideConfigurer : 重写占位符配置器
- CustomAutowireConfigurer : 自定义自动装配的配置器
- CustomScopeConfigurer : 自定义做用域的配置器
1 . 属性占位符配置器 code
看到这个 PropertyPlaceholdConfigurer 时 , 我想大多数都会想到这个标签 :blog
<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 . 重写占位符配置器io
重写占位符配置器的做用 : class
按照第一个 , 这个重写占位符配置器也应该有 Scheme 形式的简化版 : 容器
1配置