这一讲主要分析bean注册过程中各种初始化方法回调的执行逻辑(initializeBean)

    /**
* Initialize the given bean instance, applying factory callbacks
* as well as init methods and bean post processors.
* 生成bean实例,并且回调诸如init methods,bean post processors方法
* <p>Called from {@link #createBean} for traditionally defined beans,
* and from {@link #initializeBean} for existing bean instances.
* @param beanName the bean name in the factory (for debugging purposes)
* @param bean the new bean instance we may need to initialize
* @param mbd the bean definition that the bean was created with
* (can also be {@code null}, if given an existing bean instance)
* @return the initialized bean instance (potentially wrapped)
* @see BeanNameAware
* @see BeanClassLoaderAware
* @see BeanFactoryAware
* @see #applyBeanPostProcessorsBeforeInitialization
* @see #invokeInitMethods
* @see #applyBeanPostProcessorsAfterInitialization
*/
protected Object initializeBean(final String beanName, final Object bean, @Nullable RootBeanDefinition mbd) {
if (System.getSecurityManager() != null) {
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
invokeAwareMethods(beanName, bean);
return null;
}, getAccessControlContext());
}
else {
// 执行BeanNameAware,BeanClassLoaderAware,BeanFactoryAware接口方法
invokeAwareMethods(beanName, bean);
} Object wrappedBean = bean;
if (mbd == null || !mbd.isSynthetic()) {
// 执行BeanPostProcessor的postProcessBeforeInitialization方法,包括@PostConstruct注解方法
wrappedBean = applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName);
} try {
// 执行InitializingBean的afterPropertiesSet方法,包括init-method方法
invokeInitMethods(beanName, wrappedBean, mbd);
}
catch (Throwable ex) {
throw new BeanCreationException(
(mbd != null ? mbd.getResourceDescription() : null),
beanName, "Invocation of init method failed", ex);
}
if (mbd == null || !mbd.isSynthetic()) {
// 执行BeanPostProcessor的postProcessAfterInitialization方法
wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);
} return wrappedBean;
}

最新文章

  1. Java多线程之CountDownLatch学习
  2. Linux 内核编译
  3. export a java project to runable jar
  4. Javascript学习笔记:6种实现继承的方式
  5. iOS NSNotification的使用
  6. NaN 和 Infinity
  7. tlplayer for wince 版本正式商用
  8. java10 WeakHashMap
  9. centos6.6 install
  10. bzoj 1303: [CQOI2009]中位数图
  11. 向map中追加元素
  12. return机制
  13. bs4解析要获取被注掉的部分需先将注释符号去掉
  14. hadoop集群的规划和搭建
  15. 如何用golang获取linux上文件的访问/创建/修改时间
  16. grpc(三)之grpc客户端使用连接池
  17. XMLHelper类 源码(XML文档帮助类,静态方法,实现对XML文档的创建,及节点和属性的增、删、改、查)
  18. HBase数据模型的一些概念
  19. JS正则表达式方法
  20. equals与==区别

热门文章

  1. python基于django编写api+前端后端分离
  2. Jenkins打包安卓时提示没同意constraintLayout的license的解决方法
  3. shell- 字符串处理 、 扩展的脚本技巧 、 正则表达式
  4. UltraISO 9.7.0.3476中文完美破解安装版
  5. nohup 详解
  6. 112A
  7. centos7 下 apache nginx squid https正向代理 代理服务器
  8. ssh和scp时指定端口
  9. Dropout正则化和其他方法减少神经网络中的过拟合
  10. vue中清除定时器