Aop获取bean的过程---spring debug
1.调试程序:
IStudent person = (IStudent)ctx.getBean("student");
2.AbstractApplicationContext.java 执行
//---------------------------------------------------------------------// Implementation of BeanFactory interface//---------------------------------------------------------------------public Object getBean(String name) throws BeansException {return getBeanFactory().getBean(name);}
3.AbstractRefreshApplicationContext.java(getBeanFactory())和AbstractBeanFactory.java(doGetBean())
public final ConfigurableListableBeanFactory getBeanFactory() {synchronized (this.beanFactoryMonitor) {if (this.beanFactory == null) {throw new IllegalStateException("BeanFactory not initialized or already closed - " +"call 'refresh' before accessing beans via the ApplicationContext");}return this.beanFactory;}}
/*** Return an instance, which may be shared or independent, of the specified bean.* @param name the name of the bean to retrieve* @param requiredType the required type of the bean to retrieve* @param args arguments to use if creating a prototype using explicit arguments to a* static factory method. It is invalid to use a non-null args value in any other case.* @param typeCheckOnly whether the instance is obtained for a type check,* not for actual use* @return an instance of the bean* @throws BeansException if the bean could not be created*/protected Object doGetBean(final String name, final Class requiredType, final Object[] args, boolean typeCheckOnly) throws BeansException {final String beanName = transformedBeanName(name);Object bean = null;// Eagerly check singleton cache for manually registered singletons.Object sharedInstance = getSingleton(beanName);if (sharedInstance != null && args == null) {if (logger.isDebugEnabled()) {if (isSingletonCurrentlyInCreation(beanName)) {logger.debug("Returning eagerly cached instance of singleton bean '" + beanName +"' that is not fully initialized yet - a consequence of a circular reference");}else {logger.debug("Returning cached instance of singleton bean '" + beanName + "'");}}bean = getObjectForBeanInstance(sharedInstance, name, beanName, null);}else {// Fail if we're already creating this bean instance:// We're assumably within a circular reference.if (isPrototypeCurrentlyInCreation(beanName)) {throw new BeanCurrentlyInCreationException(beanName);}// Check if bean definition exists in this factory.BeanFactory parentBeanFactory = getParentBeanFactory();if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {// Not found -> check parent.String nameToLookup = originalBeanName(name);if (args != null) {// Delegation to parent with explicit args.return parentBeanFactory.getBean(nameToLookup, args);}else {// No args -> delegate to standard getBean method.return parentBeanFactory.getBean(nameToLookup, requiredType);}}if (!typeCheckOnly) {markBeanAsCreated(beanName);}final RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);checkMergedBeanDefinition(mbd, beanName, args);// Guarantee initialization of beans that the current bean depends on.String[] dependsOn = mbd.getDependsOn();if (dependsOn != null) {for (int i = 0; i < dependsOn.length; i++) {String dependsOnBean = dependsOn[i];getBean(dependsOnBean);registerDependentBean(dependsOnBean, beanName);}}// Create bean instance.if (mbd.isSingleton()) {sharedInstance = getSingleton(beanName, new ObjectFactory() {public Object getObject() throws BeansException {try {return createBean(beanName, mbd, args);}catch (BeansException ex) {// Explicitly remove instance from singleton cache: It might have been put there// eagerly by the creation process, to allow for circular reference resolution.// Also remove any beans that received a temporary reference to the bean. destroySingleton(beanName);throw ex;}}});bean = getObjectForBeanInstance(sharedInstance, name, beanName, mbd);}else if (mbd.isPrototype()) {// It's a prototype -> create a new instance.Object prototypeInstance = null;try {beforePrototypeCreation(beanName);prototypeInstance = createBean(beanName, mbd, args);}finally {afterPrototypeCreation(beanName);}bean = getObjectForBeanInstance(prototypeInstance, name, beanName, mbd);}else {String scopeName = mbd.getScope();final Scope scope = (Scope) this.scopes.get(scopeName);if (scope == null) {throw new IllegalStateException("No Scope registered for scope '" + scopeName + "'");}try {Object scopedInstance = scope.get(beanName, new ObjectFactory() {public Object getObject() throws BeansException {beforePrototypeCreation(beanName);try {return createBean(beanName, mbd, args);}finally {afterPrototypeCreation(beanName);}}});bean = getObjectForBeanInstance(scopedInstance, name, beanName, mbd);}catch (IllegalStateException ex) {throw new BeanCreationException(beanName,"Scope '" + scopeName + "' is not active for the current thread; " +"consider defining a scoped proxy for this bean if you intend to refer to it from a singleton",ex);}}}// Check if required type matches the type of the actual bean instance.if (requiredType != null && bean != null && !requiredType.isAssignableFrom(bean.getClass())) {throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());}return bean;}
转载于:https://www.cnblogs.com/davidwang456/archive/2013/03/15/2961078.html
Aop获取bean的过程---spring debug相关推荐
- Spring 管理Bean(获取Bean,初始化bean事件,自动匹配ByName······等)
1.实例化spring容器 和 从容器获取Bean对象 实例化Spring容器常用的两种方式: 方法一: 在类路径下寻找配置文件来实例化容器 [推荐使用] ApplicationContext ctx ...
- 通过Debug带你详细了解Spring创建Bean的过程,一清二楚!
Spring流程Debug 1.1 Spring测试环境搭建 Spring模块概览,绿色是模块,Spring中八大模块,黑色表示该模块包含的jar包(组件).例如我们想要用IOC容器,也就是绿色的Co ...
- Spring IOC 容器源码分析 - 创建单例 bean 的过程
1. 简介 在上一篇文章中,我比较详细的分析了获取 bean 的方法,也就是getBean(String)的实现逻辑.对于已实例化好的单例 bean,getBean(String) 方法并不会再一次去 ...
- Spring源码之getBean(获取 bean)方法(二)解读
目录 前言 `spring` 初始化 `bean` 过程 进入类 `ClassPathXmlApplicationContext` 的构造器 `AbstractApplicationContext` ...
- spring之:XmlWebApplicationContext作为Spring Web应用的IoC容器,实例化和加载Bean的过程...
它既是 DispatcherServlet 的 (WebApplicationContext)默认策略,又是 ContextLoaderListener 创建 root WebApplicationC ...
- Spring源码分析-如何获取Bean对象
导语 在上篇博客中 介绍了关于BeanFactory和FactoryBean相关的操作,并且查看了在两个操作中他们具体的代码有那些,这篇博客主要就是顺着上篇博客思路继续来分析Bean对象的获取.下 ...
- Spring源码系列(十二)Spring创建Bean的过程(二)
1.写在前面 上篇博客主要Spring在创建Bean的时候,第一次调用的Bean的后置处理器的过程,同时笔者也打算将整个Spring创建的Bean的过程,通过这个系列,将Bean的创建过程给讲清楚,废 ...
- Spring 源码解析 - Bean创建过程 以及 解决循环依赖
一.Spring Bean创建过程以及循环依赖 上篇文章对 Spring Bean资源的加载注册过程进行了源码梳理和解析,我们可以得到结论,资源文件中的 bean 定义信息,被组装成了 BeanDef ...
- Spring Bean实例化过程,怎么解决循环依赖
1.Spring是什么? Spring有很庞大的家族,Spring一般指的其实就是SpringFramework! Ioc和aop 包含在SpringFramework中! SpringFramewo ...
最新文章
- 08查找满足条件的n个数
- MX130+python3.7.6+CUDA 10.0+CUDNN 7.4.2+TensorFlow-gpu安装
- ORACLE TEXT FILTER PREFERENCE(二)
- 解决 FTPClient 出现的553错误
- java 定义全局变量_都说变量有七八种,到底谁是 Java 的亲儿子
- JVM(4):Jvm调优-命令篇
- 基于单片机的智能插座控制系统设计
- EndNote X9破解之后遇到的问题
- exe文件关联被更改的解决方法
- mysql 省份城市县区数据表SQL(包含经纬度)
- C++经典算法题-洗扑克牌(乱数排列)
- 企业薪酬 ▶管理八大痛苦八大处方
- 935.Knight Dialer [JavaScript]
- 系统升级 | RK3568开发平台成功搭载SylixOS国产实时操作系统
- 《网页制作与网站建设从入门到精通》封面
- 无心之错 过犹不及 ssh
- selinum自动化测试代码编写框架
- 企业网站设计参考文献优选范文103个
- 游戏音乐/游戏音效/游戏配音优选
- sos.exe 病毒与sos.exe专杀工具
热门文章
- 江西一级b计算机考试报名,全国计算机等级考试一级b
- 磁盘位置_CPT201-磁盘
- 如何让网页弹出确定_电脑去除网页上弹窗广告的操作方法
- php 子类名,php的继承方法获取子类名
- 计数信号量的原理与创建
- 3层vni vxlan_VLAN和VXLAN,两者有何区别?VXLAN运用场景有哪些?
- javabirdge php_PHP-Java-Bridge使用笔记,2014年9月最新版
- java split()方法_Java 性能优化的 50 个细节(珍藏版)
- mysql5.5开启binlog_MySQL开启binlog方法
- wmic 获取计算机ip,【已解决】xp系统下,受限用户如何用批处理在不使用wmic获取多个网卡的IP地址?...