spring为实现Aware接口的自动设置相关属性的操作_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > spring为实现Aware接口的自动设置相关属性的操作

spring为实现Aware接口的自动设置相关属性的操作

 2017/9/15 18:26:54  ray1205  程序员俱乐部  我要评论(0)
  • 摘要:引用AbstractApplicationContext.refresh->finishBeanFactoryInitialization->beanFactory.preInstantiateSingletons()->getBean->doGetBean->getSingleton->singletonFactory.getObject()->createBean->doCreateBean->initializeBean1
  • 标签:实现 Spring 操作 接口
引用AbstractApplicationContext.refresh->finishBeanFactoryInitialization->beanFactory.preInstantiateSingletons()->getBean->doGetBean->getSingleton->singletonFactory.getObject()->createBean->doCreateBean->initializeBean



1. initializeBean的时候调用invokeAwareMethods(beanName, bean);(org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(String, Object, RootBeanDefinition))
这时会:
1.1 调用BeanNameAware的setBeanName(beanName)方法
1.2 调用BeanClassLoaderAwarere的setBeanClassLoader(getBeanClassLoader())方法
1.3 调用BeanFactoryAware的setBeanFactory(AbstractAutowireCapableBeanFactory(AbstractAutowireCapableBeanFactory.this)方法

2 initializeBean的时候调用applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName),获取BeanPostProcessors,然后遍历调用每个posetProcessor的postProcessBeforeInitialization方法;org.springframework.context.support.ApplicationContextAwareProcessor的postProcessBeforeInitialization(Object, String)方法会执行invokeAwareInterfaces(bean)
这时会:
2.1 调用EnvironmentAware的setEnvironment(this.applicationContext.getEnvironment())方法
2.2 调用EmbeddedValueResolverAware的setEmbeddedValueResolver(new EmbeddedValueResolver(this.applicationContext.getBeanFactory())方法
2.3 调用ResourceLoaderAware的setResourceLoader(this.applicationContext)方法
2.4 调用ApplicationEventPublisherAware的setApplicationEventPublisher(this.applicationContext)方法
2.5 调用MessageSourceAware的setMessageSource(this.applicationContext)方法
2.6 调用ApplicationContextAware的setApplicationContext(this.applicationContext)方法
org.springframework.web.context.support.ServletContextAwareProcessor的postProcessBeforeInitialization(Object, String)中会完成:
2.7 调用ServletContextAware的setServletContext(getServletContext())方法
2.8 调用ServletConfigAware的setServletConfig(getServletConfig())方法
  • class='magplus' title='点击查看原始大小图片' />
  • 大小: 32.7 KB
  • 查看图片附件
发表评论
用户名: 匿名