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 ...
随机推荐
- Java 将图片转二进制再将二进制转成图片
import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOu ...
- SpringBoot2 时间类型自动格式化 自动转换
package com.archibladwitwicke.springboot2.chapter03.configurer; import com.archibladwitwicke.springb ...
- java - 分页类
pager.java package com.jspnews.util; import java.io.Serializable; import java.util.List; /** * * < ...
- PCL点云曲面重建(1)
在测量较小的数据时会产生一些误差,这些误差所造成的不规则数据如果直接拿来曲面重建的话,会使得重建的曲面不光滑或者有漏洞,可以采用对数据重采样来解决这样问题,通过对周围的数据点进行高阶多项式插值来重建表 ...
- mongoDB之监控工具mongostat
mongostat是mongdb自带的状态检测工具,在命令行下使用.它会间隔固定时间获取mongodb的当前运行状态,并输出.如果你发现数据库突然变慢或者有其他问题的话,你第一手的操作就考虑采用mon ...
- phpStudy启动失败提示:缺少VC9运行库
镜像是官方2008 64位中文版 按照提示安装了VC9以后 软件依旧无法运行阿帕奇,提示缺少VC9运行库 这是因为:64位系统除了要装64位的运行库也要装32位的运行库 32位的VC9运行库下载:ht ...
- Androidn Notification的使用,解决找不到setLatestEventInfo方法
转自:http://blog.csdn.net/songyachao/article/details/51245370#comments 今天使用4.0.3使用 Notification notifi ...
- Q-Learning
一.Q-Learning: 例子:https://www.zhihu.com/question/26408259/answer/123230350 http://ml.cs.tsinghua.edu. ...
- mxnet卷积计算
#coding:utf-8 ''' 卷积计算 ''' import mxnet as mx from mxnet.gluon import nn from mxnet import ndarray a ...
- Axiom3D:数据绑定基本流程
在前面我们学习OpenGL时,不管绘制如球,立方体,平面,地面,动画模型中最常用的几个操作有创建缓冲区,写入缓冲区.在Axiom中,相关的操作被整合与组织到VertexData,IndexData中, ...