iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >SpringBoot源码之Bean的生命周期
  • 508
分享到

SpringBoot源码之Bean的生命周期

SpringBoot之Bean的生命周期bean生命周期SpringBean生命周期 2023-05-15 17:05:26 508人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

入口方法为SpringApplication#run() 1.springApplication#run() public ConfigurableApplicationCont

入口方法为SpringApplication#run()

1.springApplication#run()


	public ConfigurableApplicationContext run(String... args) {
		long startTime = System.nanoTime();
		DefaultBootstrapContext bootstrapContext = createBootstrapContext();
		ConfigurableApplicationContext context = null;
		configureHeadlessProperty();
		SpringApplicationRunListeners listeners = getRunListeners(args);
		listeners.starting(bootstrapContext, this.mainApplicationClass);
		try {
			ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
			ConfigurableEnvironment environment = prepareEnvironment(listeners, bootstrapContext, applicationArguments);
			Banner printedBanner = printBanner(environment);
			context = createApplicationContext();
			context.setApplicationStartup(this.applicationStartup);
			prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
			refreshContext(context);
			afterRefresh(context, applicationArguments);
			Duration timeTakenToStartup = Duration.ofNanos(System.nanoTime() - startTime);
			if (this.logStartupInfo) {
				new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), timeTakenToStartup);
			}
			listeners.started(context, timeTakenToStartup);
			callRunners(context, applicationArguments);
		}
		catch (Throwable ex) {
			if (ex instanceof AbandonedRunException) {
				throw ex;
			}
			handleRunFailure(context, ex, listeners);
			throw new IllegalStateException(ex);
		}
		try {
			if (context.isRunning()) {
				Duration timeTakenToReady = Duration.ofNanos(System.nanoTime() - startTime);
				listeners.ready(context, timeTakenToReady);
			}
		}
		catch (Throwable ex) {
			if (ex instanceof AbandonedRunException) {
				throw ex;
			}
			handleRunFailure(context, ex, null);
			throw new IllegalStateException(ex);
		}
		return context;
	}

2.SpringApplication#run()=> SpringApplication#refreshContext(context)=> SpringApplication#refresh(context)=>ConfigurableApplicationContext#refresh()=>AbstractApplicationContext#refresh()

@Override
	public void refresh() throws BeansException, IllegalStateException {
		synchronized (this.startupShutdownMonitor) {
			StartupStep contextRefresh = this.applicationStartup.start("spring.context.refresh");

			// Prepare this context for refreshing.
			prepareRefresh();

			// Tell the subclass to refresh the internal bean factory.
			ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();

			// Prepare the bean factory for use in this context.
			prepareBeanFactory(beanFactory);

			try {
				// Allows post-processing of the bean factory in context subclasses.
				postProcessBeanFactory(beanFactory);

				StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");
				// Invoke factory processors reGIStered as beans in the context.
				invokeBeanFactoryPostProcessors(beanFactory);

				// Register bean processors that intercept bean creation.
				registerBeanPostProcessors(beanFactory);
				beanPostProcess.end();

				// Initialize message source for this context.
				initMessageSource();

				// Initialize event multicaster for this context.
				initApplicationEventMulticaster();

				// Initialize other special beans in specific context subclasses.
				onRefresh();

				// Check for listener beans and register them.
				registerListeners();

				// Instantiate all remaining (non-lazy-init) singletons.
				finishBeanFactoryInitialization(beanFactory);

				// Last step: publish corresponding event.
				finishRefresh();
			}

			catch (BeansException ex) {
				if (logger.isWarnEnabled()) {
					logger.warn("Exception encountered during context initialization - " +
							"cancelling refresh attempt: " + ex);
				}

				// Destroy already created singletons to avoid dangling resources.
				destroyBeans();

				// Reset 'active' flag.
				cancelRefresh(ex);

				// Propagate exception to caller.
				throw ex;
			}

			finally {
				// Reset common introspection caches in Spring's core, since we
				// might not ever need metadata for singleton beans anymore...
				resetCommonCaches();
				contextRefresh.end();
			}
		}
	}

3.SpringApplication#run()=> SpringApplication#refreshContext(context)=> SpringApplication#refresh(context)=>ConfigurableApplicationContext#refresh()=>AbstractApplicationContext#refresh()=>AbstractApplicationContext#finishBeanFactoryInitialization()=>ConfigurableListableBeanFactory#preInstantiateSingletons()=>DefaultListableBeanFactory#preInstantiateSingletons()

@Override
	public void preInstantiateSingletons() throws BeansException {
		if (logger.isTraceEnabled()) {
			logger.trace("Pre-instantiating singletons in " + this);
		}

		// Iterate over a copy to allow for init methods which in turn register new bean definitions.
		// While this may not be part of the regular factory bootstrap, it does otherwise work fine.
		List<String> beanNames = new ArrayList<>(this.beanDefinitionNames);

		// Trigger initialization of all non-lazy singleton beans...
		for (String beanName : beanNames) {
			RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
			if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {
				if (isFactoryBean(beanName)) {
					Object bean = getBean(FACTORY_BEAN_PREFIX + beanName);
					if (bean instanceof SmartFactoryBean<?> smartFactoryBean && smartFactoryBean.isEagerInit()) {
						getBean(beanName);
					}
				}
				else {
					// 此处就是初始化bean的方法
					getBean(beanName);
				}
			}
		}

		// Trigger post-initialization callback for all applicable beans...
		for (String beanName : beanNames) {
			// 此处就是解决循环依赖的代码
			Object singletonInstance = getSingleton(beanName);
			if (singletonInstance instanceof SmartInitializingSingleton smartSingleton) {
				StartupStep smartInitialize = this.getApplicationStartup().start("spring.beans.smart-initialize")
						.tag("beanName", beanName);
				smartSingleton.afterSingletonsInstantiated();
				smartInitialize.end();
			}
		}
	}

解决循环依赖的代码如下:

protected Object getSingleton(String beanName, boolean allowEarlyReference) {
// 尝试从缓存中获取成品的目标对象,如果存在,则直接返回
  Object singletonObject = this.singletonObjects.get(beanName);
  // 如果缓存中不存在目标对象,则判断当前对象是否已经处于创建过程中,在前面的讲解中,第一次尝试获取A对象
  // 的实例之后,就会将A对象标记为正在创建中,因而最后再尝试获取A对象的时候,这里的if判断就会为true
  if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {
    synchronized (this.singletonObjects) {
      singletonObject = this.earlySingletonObjects.get(beanName);
      if (singletonObject == null && allowEarlyReference) {
        // 这里的singletonFactories是一个Map,其key是bean的名称,而值是一个ObjectFactory类型的
        // 对象,这里对于A和B而言,调用图其getObject()方法返回的就是A和B对象的实例,无论是否是半成品
        ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName);
        if (singletonFactory != null) {
          // 获取目标对象的实例
          singletonObject = singletonFactory.getObject();
          this.earlySingletonObjects.put(beanName, singletonObject);
          this.singletonFactories.remove(beanName);
        }
      }
    }
  }
  return singletonObject;
}
  • 一级缓存,singletonObjects 单例缓存,存储已经实例化的单例bean。
  • 二级缓存,earlySingletonObjects 提前暴露的单例缓存,这里存储的bean是刚刚构造完成,但还会通过属性注入bean。
  • 三级缓存,singletonFactories 生产单例的工厂缓存,存储工厂。

解决原理如下:

  • 在第一层中,先去获取 A 的 Bean,发现没有就准备去创建一个,然后将 A 的代理工厂放入“三级缓存”(这个 A 其实是一个半成品,还没有对里面的属性进行注入),但是 A 依赖 B 的创建,就必须先去创建 B;
  • 在第二层中,准备创建 B,发现 B 又依赖 A,需要先去创建 A,去创建 A,因为第一层已经创建了 A 的代理工厂,直接从“三级缓存”中拿到 A 的代理工厂,获取 A 的代理对象,放入“二级缓存”,并清除“三级缓存”;
  • 有了 A 的代理对象,对 A 的依赖完美解决(这里的 A 仍然是个半成品),B 初始化成功。在 B 初始化成功,完成 A 对象的属性注入,然后再填充 A 的其它属性,以及 A 的其它步骤(包括 aop),完成对 A 完整的初始化功能(这里的 A 才是完整的 Bean)。
  • 将 A 放入“一级缓存”。

 

4.SpringApplication#run()=> SpringApplication#refreshContext(context)=> SpringApplication#refresh(context)=>ConfigurableApplicationContext#refresh()=>AbstractApplicationContext#refresh()=>AbstractApplicationContext#finishBeanFactoryInitialization()=>ConfigurableListableBeanFactory#preInstantiateSingletons()=>DefaultListableBeanFactory#preInstantiateSingletons()=>AbstractBeanFactory#getBean() => AbstractBeanFactory#doGetBean()=>AbstractBeanFactory#createBean()=>AbstractAutowireCapableBeanFactory#createBean()=>AbstractAutowireCapableBeanFactory#doCreateBean()

bean的生命周期:

1.调用InstantiationAwareBeanPostProcessor# postProcessBeforeInstantiation
跟进doCreateBean()

@Override  
protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)  
      throws BeanCreationException {  
  
   if (logger.isTraceEnabled()) {  
      logger.trace("Creating instance of bean '" + beanName + "'");  
   }  
   RootBeanDefinition mbdToUse = mbd;  
  
   // Make sure bean class is actually resolved at this point, and  
   // clone the bean definition in case of a dynamically resolved Class   // which cannot be stored in the shared merged bean definition.   Class<?> resolvedClass = resolveBeanClass(mbd, beanName);  
   if (resolvedClass != null && !mbd.hasBeanClass() && mbd.getBeanClassName() != null) {  
      mbdToUse = new RootBeanDefinition(mbd);  
      mbdToUse.setBeanClass(resolvedClass);  
   }  
  
   // Prepare method overrides.  
   try {  
      mbdToUse.prepareMethodOverrides();  
   }  
   catch (BeanDefinitionValidationException ex) {  
      throw new BeanDefinitionStoreException(mbdToUse.getResourceDescription(),  
            beanName, "Validation of method overrides failed", ex);  
   }  
  
   try {  
      // 1.调用InstantiationAwareBeanPostProcessor# postProcessBeforeInstantiation
      Object bean = resolveBeforeInstantiation(beanName, mbdToUse);  
      if (bean != null) {  
         return bean;  
      }  
   }  
   catch (Throwable ex) {  
      throw new BeanCreationException(mbdToUse.getResourceDescription(), beanName,  
            "BeanPostProcessor before instantiation of bean failed", ex);  
   }  
  
   try {  
	  // 跟进doCreateBean()
      Object beanInstance = doCreateBean(beanName, mbdToUse, args);  
      if (logger.isTraceEnabled()) {  
         logger.trace("Finished creating instance of bean '" + beanName + "'");  
      }  
      return beanInstance;  
   }  
   catch (BeanCreationException | ImplicitlyAppearedSingletonException ex) {  
      // A previously detected exception with proper bean creation context already,  
      // or illegal singleton state to be communicated up to DefaultSingletonBeanRegistry.      throw ex;  
   }  
   catch (Throwable ex) {  
      throw new BeanCreationException(  
            mbdToUse.getResourceDescription(), beanName, "Unexpected exception during bean creation", ex);  
   }  
}

2.创建bean实例

跟进populateBean()
跟进initializeBean()

protected Object doCreateBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)  
      throws BeanCreationException {  
  
   // Instantiate the bean.  
   BeanWrapper instanceWrapper = null;  
   if (mbd.isSingleton()) {  
      instanceWrapper = this.factoryBeanInstanceCache.remove(beanName);  
   }  
   if (instanceWrapper == null) { 
	  // 2.创建bean实例 
      instanceWrapper = createBeanInstance(beanName, mbd, args);  
   }  
   Object bean = instanceWrapper.getWrappedInstance();  
   Class<?> beanType = instanceWrapper.getWrappedClass();  
   if (beanType != NullBean.class) {  
      mbd.resolvedTargetType = beanType;  
   }  
  
   // Allow post-processors to modify the merged bean definition.  
   synchronized (mbd.postProcessingLock) {  
      if (!mbd.postProcessed) {  
         try {
            applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName);  
         }  
         catch (Throwable ex) {  
            throw new BeanCreationException(mbd.getResourceDescription(), beanName,  
                  "Post-processing of merged bean definition failed", ex);  
         }  
         mbd.markAsPostProcessed();  
      }  
   }  
  
   // Eagerly cache singletons to be able to resolve circular references  
   // even when triggered by lifecycle interfaces like BeanFactoryAware.   boolean earlySingletonExposure = (mbd.isSingleton() && this.allowCircularReferences &&  
         isSingletonCurrentlyInCreation(beanName));  
   if (earlySingletonExposure) {  
      if (logger.isTraceEnabled()) {  
         logger.trace("Eagerly caching bean '" + beanName +  
               "' to allow for resolving potential circular references");  
      }  
      addSingletonFactory(beanName, () -> getEarlyBeanReference(beanName, mbd, bean));  
   }  
  
   // Initialize the bean instance.  
   Object exposedObject = bean;  
   try {
	  // 跟进populateBean()
      populateBean(beanName, mbd, instanceWrapper); 
      // 跟进initializeBean() 
      exposedObject = initializeBean(beanName, exposedObject, mbd);  
   }  
   catch (Throwable ex) {  
      if (ex instanceof BeanCreationException bce && beanName.equals(bce.getBeanName())) {  
         throw bce;  
      }  
      else {  
         throw new BeanCreationException(mbd.getResourceDescription(), beanName, ex.getMessage(), ex);  
      }  
   }  
  
   if (earlySingletonExposure) {  
      Object earlySingletonReference = getSingleton(beanName, false);  
      if (earlySingletonReference != null) {  
         if (exposedObject == bean) {  
            exposedObject = earlySingletonReference;  
         }  
         else if (!this.allowRawInjectionDespiteWrapping && hasDependentBean(beanName)) {  
            String[] dependentBeans = getDependentBeans(beanName);  
            Set<String> actualDependentBeans = new LinkedHashSet<>(dependentBeans.length);  
            for (String dependentBean : dependentBeans) {  
               if (!removeSingletonIfCreatedForTypeCheckOnly(dependentBean)) {  
                  actualDependentBeans.add(dependentBean);  
               }  
            }  
            if (!actualDependentBeans.isEmpty()) {  
               throw new BeanCurrentlyInCreationException(beanName,  
                     "Bean with name '" + beanName + "' has been injected into other beans [" +  
                     StringUtils.collectionToCommaDelimitedString(actualDependentBeans) +  
                     "] in its raw version as part of a circular reference, but has eventually been " +  
                     "wrapped. This means that said other beans do not use the final version of the " +  
                     "bean. This is often the result of over-eager type matching - consider using " +  
                     "'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.");  
            }  
         }  
      }  
   }  
  
   // Register bean as disposable.  
   try {  
      registerDisposableBeanIfNecessary(beanName, bean, mbd);  
   }  
   catch (BeanDefinitionValidationException ex) {  
      throw new BeanCreationException(  
            mbd.getResourceDescription(), beanName, "Invalid destruction signature", ex);  
   }  
  
   return exposedObject;  
}

3.调用InstantiationAwareBeanPostProcessor# postProcessAfterInstantiation

4.注入bean属性

protected void populateBean(String beanName, RootBeanDefinition mbd, @Nullable BeanWrapper bw) {  
   if (bw == null) {  
      if (mbd.hasPropertyValues()) {  
         throw new BeanCreationException(  
               mbd.getResourceDescription(), beanName, "Cannot apply property values to null instance");  
      }  
      else {  
         // Skip property population phase for null instance.  
         return;  
      }  
   }  
  
   if (bw.getWrappedClass().isRecord()) {  
      if (mbd.hasPropertyValues()) {  
         throw new BeanCreationException(  
               mbd.getResourceDescription(), beanName, "Cannot apply property values to a record");  
      }  
      else {  
         // Skip property population phase for records since they are immutable.  
         return;  
      }  
   }  
  
      // 3.调用InstantiationAwareBeanPostProcessor# postProcessAfterInstantiation
      for (InstantiationAwareBeanPostProcessor bp : getBeanPostProcessorCache().instantiationAware) {  
         if (!bp.postProcessAfterInstantiation(bw.getWrappedInstance(), beanName)) {  
            return;  
         }  
      }  
   }  
  
   PropertyValues pvs = (mbd.hasPropertyValues() ? mbd.getPropertyValues() : null);  
  
   int resolvedAutowireMode = mbd.getResolvedAutowireMode();  
   if (resolvedAutowireMode == AUTOWIRE_BY_NAME || resolvedAutowireMode == AUTOWIRE_BY_TYPE) {  
      MutablePropertyValues newPvs = new MutablePropertyValues(pvs);  
      // Add property values based on autowire by name if applicable.  
      if (resolvedAutowireMode == AUTOWIRE_BY_NAME) {  
         autowireByName(beanName, mbd, bw, newPvs);  
      }  
      // Add property values based on autowire by type if applicable.  
      if (resolvedAutowireMode == AUTOWIRE_BY_TYPE) {  
         autowireByType(beanName, mbd, bw, newPvs);  
      }  
      pvs = newPvs;  
   }  
   if (hasInstantiationAwareBeanPostProcessors()) {  
      if (pvs == null) { 
         pvs = mbd.getPropertyValues();  
      }  
      for (InstantiationAwareBeanPostProcessor bp : getBeanPostProcessorCache().instantiationAware) {  
         PropertyValues pvsToUse = bp.postProcessProperties(pvs, bw.getWrappedInstance(), beanName);  
         if (pvsToUse == null) {  
            return;  
         }  
         pvs = pvsToUse;  
      }  
   }  
  
   boolean needsDepCheck = (mbd.getDependencyCheck() != AbstractBeanDefinition.DEPENDENCY_CHECK_NONE);  
   if (needsDepCheck) {  
      PropertyDescriptor[] filteredPds = filterPropertyDescriptorsForDependencyCheck(bw, mbd.allowCaching);  
      checkDependencies(beanName, mbd, filteredPds, pvs);  
   }  
  
   if (pvs != null) {
	  // 4.注入属性  
      applyPropertyValues(beanName, mbd, bw, pvs);  
   }  
}

5.设置Aware接口的属性

6.调用BeanPostProcessor的初始化前置方法

7.先((InitializingBean) bean).afterPropertiesSet(),后调用init-method方法,进行初始化操作

8.调用BeanPostProcessor的初始化后置方法

protected Object initializeBean(String beanName, Object bean, @Nullable RootBeanDefinition mbd) {
    // 5.设置Aware接口的属性
   invokeAwareMethods(beanName, bean);  
  
   Object wrappedBean = bean;  
   if (mbd == null || !mbd.isSynthetic()) {
	  // 5.调用BeanPostProcessor的初始化前置方法  
      wrappedBean = applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName);  
   }  
  
   try {
	  // 6.调用init-method方法,进行初始化操作  
      invokeInitMethods(beanName, wrappedBean, mbd);  
   }  
   catch (Throwable ex) {  
      throw new BeanCreationException(  
            (mbd != null ? mbd.getResourceDescription() : null), beanName, ex.getMessage(), ex);  
   }  
   if (mbd == null || !mbd.isSynthetic()) { 
      // 7. 调用BeanPostProcessor的初始化后置方法
      wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);  
   }  
  
   return wrappedBean;  
}

以上就是SpringBoot源码之Bean的生命周期的详细内容,更多关于SpringBoot Bean生命周期的资料请关注编程网其它相关文章!

--结束END--

本文标题: SpringBoot源码之Bean的生命周期

本文链接: https://www.lsjlt.com/news/209318.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • SpringBoot源码之Bean的生命周期
    入口方法为SpringApplication#run() 1.SpringApplication#run() public ConfigurableApplicationCont...
    99+
    2023-05-15
    SpringBoot之Bean的生命周期 bean生命周期 SpringBean生命周期
  • SpringBoot源码之Bean的生命周期是什么
    本文小编为大家详细介绍“SpringBoot源码之Bean的生命周期是什么”,内容详细,步骤清晰,细节处理妥当,希望这篇“SpringBoot源码之Bean的生命周期是什么”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知...
    99+
    2023-07-06
  • Spring源码解析之Bean的生命周期
    一、Bean的实例化概述 前一篇分析了BeanDefinition的封装过程,最终将beanName与BeanDefinition以一对一映射关系放到beanDefinitionMa...
    99+
    2024-04-02
  • Spring Bean生命周期源码分析
    这篇“Spring Bean生命周期源码分析”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Spring ...
    99+
    2023-07-05
  • Java之Spring Bean作用域和生命周期源码分析
    这篇文章主要讲解了“Java之Spring Bean作用域和生命周期源码分析”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Java之Spring Bean作用域和生命周期...
    99+
    2023-07-05
  • spring之Bean的生命周期详解
    Bean的生命周期:Bean的定义——Bean的初始化——Bean的使用——Bean的销毁Bean的定义Bean 是 spring 装配的组件模型,一切实体类都可以配置成一个 Bean ,进而就可以在任何其他的 Bean 中使用,一个 Be...
    99+
    2023-05-31
    spring bean 生命周期
  • Bean 的生命周期总结
      目录 一、Bean生命周期的五个阶段 Bean的初始化 二、@PostConstruct 和 @PreDestroy 各自的效果 三、 实例化和初始化的区别 四、为什么要先设置属性在进⾏初始化呢? 一、Bea...
    99+
    2023-09-10
    java 开发语言 spring
  • Java之Bean的生命周期实例分析
    本篇内容主要讲解“Java之Bean的生命周期实例分析”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Java之Bean的生命周期实例分析”吧!一、什么是生命周期首先理解下什么是生命周期从创建到消...
    99+
    2023-07-02
  • SpringBean生命周期之Bean的注册详解
    目录前言BeanFactory的继承体系Bean的注册alias别名的注册总结前言 上篇文章介绍了Bean元信息的配置与解析过程,限于篇幅Bean注册过程就没展开。 这里主要围绕Be...
    99+
    2024-04-02
  • Spring中bean的生命周期之getSingleton方法
    Spring中bean的生命周期 要想讲清楚spring中bean的生命周期,真的是不容易,以AnnotationConfigApplicationContext上下文为基础来讲解b...
    99+
    2024-04-02
  • 【Spring】Spring的Bean的生命周期
    作者简介:大家好,我是五度鱼,一个普通的Java领域博主,不停输出Java技术博客和干货。座右铭:锲而不舍,金石可镂。个人主页:五度鱼学Java的主页 文章目录 前言1. 什么是Bean的生命周期?2. 为什么要知道Bean...
    99+
    2023-08-17
    java Bean生命周期 spring
  • SpringBean生命周期之Bean的实例化详解
    目录前言实例化前阶段实例化阶段实例化后阶段总结前言 上一节说到了BeanDefinition的合并过程,这节该说Bean的实例化过程了。根据AbstractAutowireCapab...
    99+
    2024-04-02
  • rust生命周期源码分析
    本文小编为大家详细介绍“rust生命周期源码分析”,内容详细,步骤清晰,细节处理妥当,希望这篇“rust生命周期源码分析”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。rust生命周期生命周期是rust中用来规定引...
    99+
    2023-07-05
  • Spring bean的生命周期是什么
    Spring bean的生命周期包括以下阶段:1. 实例化(Instantiation):在容器启动时,Spring根据配置信息或注...
    99+
    2023-08-24
    Spring bean
  • Spring Bean的生命周期是什么
    这篇“Spring Bean的生命周期是什么”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Spring ...
    99+
    2023-07-05
  • Spring 中 Bean 的生命周期详解
    目录前言1.Bean 生命周期2.代码演示总结前言 Java 中的公共类称之为 Bean 或 Java Bean,而 Spring 中的 Bean 指的是将对象的生命周期,交个 Sp...
    99+
    2024-04-02
  • Java开发学习之Bean的生命周期详解
    目录一、什么是生命周期二、环境准备三、生命周期设置步骤1:添加初始化和销毁方法步骤2:配置生命周期步骤3:运行程序四、close关闭容器五、注册钩子关闭容器六、bean生命周期总结一...
    99+
    2024-04-02
  • Spring Bean生命周期,好像人的一生。。
    大家好,我是老三,上节我们手撸了一个简单的IOC容器五分钟,手撸一个Spring容器!,这节我们来看一看Spring中Bean的生命周期,我发现,和人的一生真的很像。 简单说说IoC和Bean IoC...
    99+
    2023-09-27
    spring java 后端
  • Spring Bean的生命周期 -- Spring入门(三)
    文章目录 前言1. 理解bean的生命周期2. Bean 生命周期的执行过程3. Bean生命周期控制入门案例4. 关闭IOC容器的两种方式5. 通过继承接口绑定生命周期方法 总结 前言 为了巩固所学的知识,作者尝试着开始...
    99+
    2023-08-17
    spring java 后端
  • 深入了解Spring的Bean生命周期
    目录源码下载什么是 Spring Bean 的生命周期Bean的生命周期Spring角度查看bean的定义与注册SpringBoot角度查看bean定义和注册实例化,依赖注入,初始化...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作