zoukankan      html  css  js  c++  java
  • Spring中重要的核心类和设计理念

      Spring中又两个看着相似的接口,BeanFactory,FactoryBean,它们到底有什么作用和区别呢?

      Spring中管理的Bean是由什么类解析呢?答案就是BeanFactory。

      打开AbstractApplicationContext类,看refresh方法:

     public void refresh() throws BeansException, IllegalStateException {
            synchronized(this.startupShutdownMonitor) {
                this.prepareRefresh();
                ConfigurableListableBeanFactory beanFactory = this.obtainFreshBeanFactory();
                this.prepareBeanFactory(beanFactory);
    
                try {
                    this.postProcessBeanFactory(beanFactory);
                    this.invokeBeanFactoryPostProcessors(beanFactory);
                    this.registerBeanPostProcessors(beanFactory);
                    this.initMessageSource();
                    this.initApplicationEventMulticaster();
                    this.onRefresh();
                    this.registerListeners();
              // 创建BeanFactory,就相当于创建一个汽车制造厂。 this.finishBeanFactoryInitialization(beanFactory); this.finishRefresh(); } catch (BeansException var9) { if (this.logger.isWarnEnabled()) { this.logger.warn("Exception encountered during context initialization - cancelling refresh attempt: " + var9); } this.destroyBeans(); this.cancelRefresh(var9); throw var9; } finally { this.resetCommonCaches(); } } }

      可以看到创建bean和销毁bean的过程。  

    参考资料 《深入分析javaWeb》

  • 相关阅读:
    09-23
    21-9-18日记1
    paho mqtt库使用记录
    UIS8811 的 NB-IOT 初认识(21-9-10工作记录 )
    go语言之异常捕获
    【原创】数据库基础之PostgreSQL
    【原创】Linux基础之fail2ban
    【原创】大叔经验分享(132)mac os 12启动idea失败
    【原创】大数据基础之Hadoop(3)hdfs diskbalancer
    【转】常用 Git 命令清单
  • 原文地址:https://www.cnblogs.com/Robin008/p/12500513.html
Copyright © 2011-2022 走看看