8 -- 深入使用Spring -- 1...3 容器后处理器
8.1.3 容器后处理器(BeanFactoryPostProcessor)
容器后处理器负责处理容器本身。
容器后处理器必须实现BeanFacotryPostProcessor接口。实现该接口必须实现如下一个方法:
postProcessBeanFactory(ConfigurableListableBeanFacotry beanFactory) :该方法只是对Spring容器进行后处理,无须任何返回值。
ApplicationContext可自动检测到容器中的容器后处理器,并自动注册容器后处理器。但若使用BeanFactory作为Spring容器,则必须手动调用该容器后处理器来处理BeanFactory容器。
Class : MyBeanFactoryPostProcessor
package edu.pri.lime._8_1_3; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
System.out.println("程序对Spring所做的BeanFactory的初始化没有改变...");
System.out.println("Spring容器是:" + beanFactory);
} }
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"> <bean class="edu.pri.lime._8_1_3.MyBeanFactoryPostProcessor" /> </beans>
Class : BeanTest
package edu.pri.lime._8_1_3.main;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class BeanTest {
@SuppressWarnings("resource")
public static void main(String[] args) {
new ClassPathXmlApplicationContext("app_8_1_3.xml");
}
}
Console :
二月 09, 2017 9:02:57 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2752f6e2: startup date [Thu Feb 09 21:02:57 CST 2017]; root of context hierarchy
二月 09, 2017 9:02:57 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [app_8_1_3.xml]
程序对Spring所做的BeanFactory的初始化没有改变...
Spring容器是:org.springframework.beans.factory.support.DefaultListableBeanFactory@3aefe5e5: defining beans [edu.pri.lime._8_1_3.MyBeanFactoryPostProcessor#0]; root of factory hierarchy
Spring已提供如下几个常用的容器后处理器:
⊙ PropertyPlaceholderConfigurer : 属性占位符配置器。
⊙ PropertyOverrideConfigurer : 重写占位符配置器。
⊙ CustomAutowireConfigurer : 自定义自动装配的配置器。
⊙ CustomScopeConfigurer : 自定义作用域的配置器。
容器后处理器通常用于对Spring容器进行处理,并且总是在容器实例化任何其他Bean之前,读取配置文件的元数据,并有可能修改这些元数据。
如果有需要,程序可以配置多个容器后处理器,多个容器后处理器可设置order属性来控制容器后处理的执行次序。
为了给容器后处理器指定order属性,则要求容器后处理器必须实现Ordered接口,因此在实现BeanFactoryPostProcessor时,就应当考虑实现Ordered接口。
容器后处理器的作用域范围是容器级,它只对容器本身进行处理,而不对容器中的Bean进行处理;
啦啦啦
8 -- 深入使用Spring -- 1...3 容器后处理器的更多相关文章
- 半夜思考之查漏补缺, Spring 中的容器后处理器
之前学 Spring 的时候 , 还没听过容器后处理器 , 但是一旦写出来 , 就会觉得似曾相识 . 容器配置器通常用于对 Spring 容器进行处理 , 并且总是在容器实例化任何其他 Bean 之前 ...
- Spring Bean后处理器以及容器后处理器【转】
Bean后处理器:即当spring容器实例化Bean实例之后进行的增强处理. 容器后处理器:对容器本身进行处理,并总是在容器实例化其他任何Bean之前读取配置文件的元数据并可能修改这些数据. 一.Be ...
- 8 -- 深入使用Spring -- 1...两种后处理器
8.1 两种后处理器 Spring框架提供了很好的扩展性,出了可以与各种第三方框架良好整合外,其IoC容器也允许开发者进行扩展,这种扩展甚至无须实现BeanFactor或ApplicationCont ...
- 品Spring:详细解说bean后处理器
一个小小的里程碑 首先感谢能看到本文的朋友,感谢你的一路陪伴. 如果每篇都认真看的话,会发现本系列以bean定义作为切入点,先是详细解说了什么是bean定义,接着又强调了bean定义为什么如此重要. ...
- Spring - BeanPostProcessor接口(后处理器)讲解
概述: BeanPostProcessor接口是众多Spring提供给开发者的bean生命周期内自定义逻辑拓展接口中的一个,其他还有类似InitializingBean,DisposableBean, ...
- 8 -- 深入使用Spring -- 1...2 Bean后处理器的用处
8.1.2 Bean后处理器的用处 Spring提供的两个常用的后处理器: ⊙ BeanNameAutoProxyCreator : 根据Bean实例的name属性,创建Bean实例的代理. ⊙ De ...
- 品Spring:bean工厂后处理器的调用规则
上一篇文章介绍了对@Configuration类的处理逻辑,这些逻辑都写在ConfigurationClassPostProcessor类中. 这个类不仅是一个“bean工厂后处理器”,还是一个“be ...
- spring中的bean后处理器
package com.process; import org.springframework.beans.BeansException; import org.springframework.bea ...
- spring4笔记----Spring几种常用的容器后处理器
PropertyPlaceholderConfigurer 属性占位符配置器 PropertyOverrideConfigureer 重写占位符配置器 CustomAutowireConfig ...
随机推荐
- sqoop 常见错误以及处理方式
Oracle: Connection Reset Errors 错误代码 // :: INFO mapred.JobClient: Task Id : attempt_201105261333_000 ...
- fiddler手机端抓包
1. 买个360随身wifi,插在台式机上生成热点,手机连上自己的wifi 如果电脑与手机本就在一个局域网,省略这一步 2. 在fiddler中如下设置: 3. 查看电脑无线连接属性 4. 在手机上设 ...
- Java嵌入式数据库H2学习总结
H2数据库使用总结 —— 孤傲苍狼
- scrapy爬虫出现Forbidden by robots.txt
scrapy爬虫出现Forbidden by robots.txt
- Remove 以及dorp做实验验证MongoDB删除文档后索引是否会自动删除
下面是实验步骤: > db.things.find(){ "_id" : ObjectId("5652d71a1524dc14663060e8"), &q ...
- SSH-CLIENT : gSTM
Linux环境下可以使用终端命令行直接登录SSH帐号.但是对Linux新手,可能不太习惯用命令行,于是我就琢磨找一款Linux环境下可以图形化管理ssh帐号的客户端软件,还真让我找着了. gSTM,是 ...
- 关于Unity中FPS第一人称射击类游戏制作(专题十)
当前Unity最新版本5.6.3f1,我使用的是5.5.1f1 场景搭建 1: 导入人物模型, 手持一把枪;2: 导入碎片模型;3: 创建一个平面;4: 创建一个障碍物;5: 导入人物模型;6: 配置 ...
- confluence + 禅道安装教程
都是从网上拿的 1. 搭建confluence BE82-LO81-4O25-THDD AAABMQ0ODAoPeJxtkE1rwzAMhu/+FYadXepkYd3AsDQ2rCwfZUkHO7qp ...
- Android notifyDataSetChanged
notifyDataSetChanged()用于动态的更新ListView中的数据.最后还是会调用Adapter中的getView函数. notifyDataSetChanged()相比于setAda ...
- Deep Residual Learning for Image Recognition这篇文章
作者:何凯明等,来自微软亚洲研究院: 这篇文章为CVPR的最佳论文奖:(conference on computer vision and pattern recognition) 在神经网络中,常遇 ...