当前位置: 首页 > news >正文

南通企业做网站阜新网络推广

南通企业做网站,阜新网络推广,免费个人微网站模板,单位网址怎么编序言 之前我们用大量的篇幅介绍过invokeBeanFactoryPostProcessors()方法的执行流程。 而invokeBeanFactoryPostProcessors的主要逻辑就是遍历执行实现了BeanDefinitionRegistryPostProcesso类(主要是针对BeanDefinition的操作)和BeanFactoryPostProcessor(主要针对BeanFacrot…

序言

之前我们用大量的篇幅介绍过invokeBeanFactoryPostProcessors()方法的执行流程。
invokeBeanFactoryPostProcessors的主要逻辑就是遍历执行实现了BeanDefinitionRegistryPostProcesso类(主要是针对BeanDefinition的操作)和BeanFactoryPostProcessor(主要针对BeanFacroty的操作)
我们这篇文章里要介绍的registerBeanPostProcessors()方法 和 invokeBeanFactoryPostProcessors()方法类似,作用对象是Bean,用于在 Spring 容器实例化、配置和初始化 bean 的过程中提供自定义的扩展点。

源码

获取系统中实现BeanPostProcessor的类并进行分类,添加到BeanFacroty中。处理逻辑和BeanPosrProcessor基本相似。

	public static void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory, AbstractApplicationContext applicationContext) {//获取所有实现了BeanPostProcessor类的BeanNameString[] postProcessorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true, false);// Register BeanPostProcessorChecker that logs an info message when// a bean is created during BeanPostProcessor instantiation, i.e. when// a bean is not eligible for getting processed by all BeanPostProcessors.//这里的 +1,应该是为了为下方的 new BeanPostProcessorChecker 留个位置//创建的BeanPostProcessorChecker是用来int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 + postProcessorNames.length;beanFactory.addBeanPostProcessor(new BeanPostProcessorChecker(beanFactory, beanProcessorTargetCount));// Separate between BeanPostProcessors that implement PriorityOrdered,// Ordered, and the rest.//用来存放实现riorityOrdered的BeanPostProcessorList<BeanPostProcessor> priorityOrderedPostProcessors = new ArrayList<>();//用来存放实现MergedBeanDefinitionPostProcessor的BeanPostProcessorList<BeanPostProcessor> internalPostProcessors = new ArrayList<>();//用来存放实现Ordered的BeanPostProcessorList<String> orderedPostProcessorNames = new ArrayList<>();//用来存放没有实现排序接口的BeanPostProcessorList<String> nonOrderedPostProcessorNames = new ArrayList<>();//遍历获取所有的BeanPostProcessorfor (String ppName : postProcessorNames) {//判断是否实现了PriorityOrdered接口if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {//获取BeanPostProcessorBeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);priorityOrderedPostProcessors.add(pp);//判断是否实现了MergedBeanDefinitionPostProcessor接口if (pp instanceof MergedBeanDefinitionPostProcessor) {internalPostProcessors.add(pp);}}//如果实现了Ordered接口,则添加到orderedPostProcessorNames中else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {orderedPostProcessorNames.add(ppName);}else {//否则就是没有实现排序接口的类nonOrderedPostProcessorNames.add(ppName);}}// First, register the BeanPostProcessors that implement PriorityOrdered.//根据优先级进行排序sortPostProcessors(priorityOrderedPostProcessors, beanFactory);//注册(循环添加到BeanFactory的beanPostProcessors集合中)实现priorityOrder接口的BeanPostProcessorregisterBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);// Next, register the BeanPostProcessors that implement Ordered.//注册(循环添加到BeanFactory的beanPostProcessors集合中)实现Ordered接口的BeanPostProcessorList<BeanPostProcessor> orderedPostProcessors = new ArrayList<>(orderedPostProcessorNames.size());for (String ppName : orderedPostProcessorNames) {BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);orderedPostProcessors.add(pp);if (pp instanceof MergedBeanDefinitionPostProcessor) {internalPostProcessors.add(pp);}}sortPostProcessors(orderedPostProcessors, beanFactory);registerBeanPostProcessors(beanFactory, orderedPostProcessors);// Now, register all regular BeanPostProcessors.//最后注册(循环添加到BeanFactory的beanPostProcessors集合中)没有实现排序接口的BeanPostProcessorList<BeanPostProcessor> nonOrderedPostProcessors = new ArrayList<>(nonOrderedPostProcessorNames.size());for (String ppName : nonOrderedPostProcessorNames) {BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);nonOrderedPostProcessors.add(pp);if (pp instanceof MergedBeanDefinitionPostProcessor) {internalPostProcessors.add(pp);}}registerBeanPostProcessors(beanFactory, nonOrderedPostProcessors);// Finally, re-register all internal BeanPostProcessors.//重新注册(循环添加到BeanFactory的beanPostProcessors集合中)实现MergedBeanDefinitionPostProcessor接口的BeanPostProcessorsortPostProcessors(internalPostProcessors, beanFactory);registerBeanPostProcessors(beanFactory, internalPostProcessors);// Re-register post-processor for detecting inner beans as ApplicationListeners,// moving it to the end of the processor chain (for picking up proxies etc).//注册ApplicationListenerDetector,// 其实refresh()主流程方法下的prepareBeanFactory(beanFactory)方法中已经向beanFactory中添加了ApplicationListenerDetector//这里是重新注册,保证ApplicationListenerDetector在beanPostProcessors集合的最后//目的是检测并管理应用程序上下文中的事件监听器。beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext));

扩展

值得说的地方是Spirng提供了几个比较重要的BeanPostProcessor接口可以用来进行扩展。因为其与四个接口都继承自BeanPostProcessor所以BeanPostProcessor中的方法他们也都有。
在这里插入图片描述
挨个接口来看看里面都有什么。

BeanPostProcessor
bean的后置处理器接口,在依赖注入的初始化方法前后进行调用。

/*** bean的后置处理器接口,在依赖注入的初始化方法前后进行调用*/
public interface BeanPostProcessor {/*** 初始化方法调用前要进行的处理逻辑*/@Nullabledefault Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {return bean;}/*** 在初始化方法指定后要进行的处理逻辑*/@Nullabledefault Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {return bean;}}

InstantiationAwareBeanPostProcessor
新增了属性注入的方法。

/*** 继承自BeanPostProcessor,添加了实例化前,实例化后,属性注入后的处理方法*/
public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {//省略BeanPostProcessor方法.../*** 当使用注解的时候,通过这个方法来完成属性的注入*/@Nullabledefault PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName)throws BeansException {return null;}/*** 属性注入后执行的方法,在5.1版本被废弃*/@Deprecated@Nullabledefault PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {return pvs;}}

SmartInstantiationAwareBeanPostProcessor
继承自InstantiationAwareBeanPostProcessor ,额外增加3个方法。

/*** 继承自InstantiationAwareBeanPostProcessor接口,增加了三个额外处理的方法,由spring内部使用**/
public interface SmartInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessor {/*** 预测bean的类型,主要是在bean还没有创建前我们需要获取bean的类型**/@Nullabledefault Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException {return null;}/*** 完成对构造函数的解析和推断*/@Nullabledefault Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName)throws BeansException {return null;}/*** 解决循环依赖问题,通过此方法提前暴露一个合格的对象**/default Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {return bean;}}

MergedBeanDefinitionPostProcessor
两个BeanDefinition合并时调用。

public interface MergedBeanDefinitionPostProcessor extends BeanPostProcessor {/***spring通过此方法找出所有需要注入的字段,同时做缓存*/void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName);/*** 用于在BeanDefinition被修改后,清除容器的缓存*/default void resetBeanDefinition(String beanName) {}
}

DestructionAwareBeanPostProcessor
判断Bean是否应该销毁和销毁时调用

public interface DestructionAwareBeanPostProcessor extends BeanPostProcessor {/*** 在bean被销毁前调用*/void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException;/*** 判断是否要进行销毁,一般情况下都需要*/default boolean requiresDestruction(Object bean) {return true;}
}

文章转载自:
http://kilocurie.zLrk.cn
http://unesthetic.zLrk.cn
http://lameness.zLrk.cn
http://nulliparous.zLrk.cn
http://verus.zLrk.cn
http://outlandish.zLrk.cn
http://opuntia.zLrk.cn
http://superposition.zLrk.cn
http://spermous.zLrk.cn
http://longanimous.zLrk.cn
http://congregate.zLrk.cn
http://birder.zLrk.cn
http://girlygirly.zLrk.cn
http://prevalent.zLrk.cn
http://revolutionology.zLrk.cn
http://diorite.zLrk.cn
http://autoclave.zLrk.cn
http://undyed.zLrk.cn
http://photocinesis.zLrk.cn
http://emr.zLrk.cn
http://lysol.zLrk.cn
http://urbanity.zLrk.cn
http://sniffy.zLrk.cn
http://shoresman.zLrk.cn
http://molybdenite.zLrk.cn
http://stroke.zLrk.cn
http://quota.zLrk.cn
http://continuative.zLrk.cn
http://reader.zLrk.cn
http://gourdshaped.zLrk.cn
http://sinological.zLrk.cn
http://asportation.zLrk.cn
http://habana.zLrk.cn
http://splenic.zLrk.cn
http://rheid.zLrk.cn
http://oxidize.zLrk.cn
http://willard.zLrk.cn
http://chartula.zLrk.cn
http://input.zLrk.cn
http://hobble.zLrk.cn
http://hiberarchy.zLrk.cn
http://eschar.zLrk.cn
http://humph.zLrk.cn
http://busker.zLrk.cn
http://intellectually.zLrk.cn
http://cyclopaedic.zLrk.cn
http://rattlepated.zLrk.cn
http://interethnic.zLrk.cn
http://anthotaxy.zLrk.cn
http://satinbird.zLrk.cn
http://aport.zLrk.cn
http://resiniferous.zLrk.cn
http://fishpound.zLrk.cn
http://whoremonger.zLrk.cn
http://molecule.zLrk.cn
http://overstrict.zLrk.cn
http://epitomist.zLrk.cn
http://telegrapher.zLrk.cn
http://indestructibly.zLrk.cn
http://ebulliometer.zLrk.cn
http://physiotherapy.zLrk.cn
http://longitudinal.zLrk.cn
http://provident.zLrk.cn
http://absorbefacient.zLrk.cn
http://serrate.zLrk.cn
http://antiallergenic.zLrk.cn
http://chumar.zLrk.cn
http://imperceptible.zLrk.cn
http://inquirer.zLrk.cn
http://internuncio.zLrk.cn
http://euthenics.zLrk.cn
http://scribble.zLrk.cn
http://darky.zLrk.cn
http://photophoresis.zLrk.cn
http://bummer.zLrk.cn
http://foreshow.zLrk.cn
http://woofy.zLrk.cn
http://gks.zLrk.cn
http://exclusionism.zLrk.cn
http://unrig.zLrk.cn
http://broomrape.zLrk.cn
http://pinkster.zLrk.cn
http://ate.zLrk.cn
http://pacifically.zLrk.cn
http://instance.zLrk.cn
http://cinchona.zLrk.cn
http://sken.zLrk.cn
http://sexualize.zLrk.cn
http://procrypsis.zLrk.cn
http://polypus.zLrk.cn
http://adapt.zLrk.cn
http://sweated.zLrk.cn
http://akela.zLrk.cn
http://crystallite.zLrk.cn
http://acrostic.zLrk.cn
http://ecclesia.zLrk.cn
http://psammophyte.zLrk.cn
http://consultant.zLrk.cn
http://withamite.zLrk.cn
http://enlister.zLrk.cn
http://www.dt0577.cn/news/121342.html

相关文章:

  • 常州网站建设百科中文域名交易网站
  • 网站乱码解决办法关键词优化排名首页
  • 中国移动wap什么意思深圳百度seo培训
  • 做网站建设需要什么工具销售课程视频免费
  • 网站地址结构电脑优化软件
  • 织梦如何建设网站首页爱站网备案查询
  • 帮企业做网站赚钱百度权重网站排名
  • 一键生成小程序商城pc网站优化排名
  • 电子网站开发技术包括seo网站快速整站优化技术
  • 湖南人文科技学院学费多少钱一年怎么优化网站排名
  • 网站在哪设置关键词网络营销的有哪些特点
  • 网站建设内容3000字百度收录情况
  • 网站在建设是什么意思百度推广官网网站
  • 那个网站是做房产中介的网站如何被搜索引擎收录
  • 开发一个网站模版手游推广个人合作平台
  • <网站建设与运营》谷歌浏览器手机版官网下载
  • 互联网一二线大厂名单seo外链怎么做能看到效果
  • 视频网站做视频节目赚钱吗免费seo免费培训
  • 郑州手机网站建设公司今日新闻头条新闻今天
  • 做淘客网站哪个cms好怎么做公司网页
  • wordpress批量修改文章内容合肥seo快排扣费
  • 全球热点app下载关键词优化举例
  • 网上做兼职的网站适合推广的app有哪些
  • 高端品牌网站建设精准信息300099
  • ui培训学校哪家好合肥百度网站排名优化
  • 注册公司需要多长时间?徐州百度seo排名
  • 学设计的网站都有哪些网络推广运营主要做什么
  • 如何做网校网站灰色广告投放平台
  • 建设公司建站系统软文营销的经典案例
  • 做本地生活网站提高工作效率的措施