当前位置: 首页 > news >正文

北京企业网站推广哪家好西安百度竞价开户

北京企业网站推广哪家好,西安百度竞价开户,wordpress 中英双语,设计类网站app本文基于Spring5.3.7 参考: kykangyuky Spring中bean的生命周期 阿斌Java之路 SpringBean的生命周期, 杨开振 JavaEE互联网轻量级框架整合开发 黑马程序员 JavaEE企业级应用开发教程 马士兵 Spring源码讲解 一. SpringBean生命周期流程图 二. 示例代码 …

本文基于Spring5.3.7

参考:
kykangyuky Spring中bean的生命周期
阿斌Java之路 SpringBean的生命周期,
杨开振 JavaEE互联网轻量级框架整合开发
黑马程序员 JavaEE企业级应用开发教程
马士兵 Spring源码讲解

一. SpringBean生命周期流程图

SpringBean生命周期流程

二. 示例代码

1. 定义果汁描述实体类

package com.xiaobai.spring_bean_life_cycle;import lombok.Data;
import lombok.extern.slf4j.Slf4j;/*** @author wangtw* @date 2023/6/24 16:38* @description 果汁描述实体类*/
@Slf4j
@Data
public class Source {public Source() {log.info("source实例化");}/*** 水果*/private String fruit;/*** 糖量*/private String sugar;/*** 大小*/private String size;
}

2. 定义果汁生成器

package com.xiaobai.spring_bean_life_cycle;import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;/*** @author wangtw* @date 2023/6/24 16:28* @description 果汁生成器*/
@Slf4j
@Data
public class JuiceMaker implements BeanNameAware, BeanFactoryAware,ApplicationContextAware, InitializingBean, DisposableBean {public JuiceMaker(){log.info("juice实例化");}private String beverageShop;private Source source;/*** 自定义初始化方法*/public void init() {log.info("【{}】执行自定义初始化方法", this.getClass().getSimpleName());}/*** 自定义销毁方法*/public void myDestroy() {log.info("【{}】执行自定义销毁方法", this.getClass().getSimpleName());}public String makeJuice() {String juice = "这是一杯由" + beverageShop + "饮品店,提供的" + source.getSize() + source.getSugar() + source.getFruit();return juice;}@Overridepublic void setBeanFactory(BeanFactory beanFactory) throws BeansException {log.info("【{}】调用BeanFactoryAware接口的setBeanFactory方法", this.getClass().getSimpleName());}@Overridepublic void setBeanName(String s) {log.info("【{}】调用BeanNameAware接口的setBeanName方法", this.getClass().getSimpleName());}@Overridepublic void destroy() throws Exception {log.info("调用接口DisposableBean的destroy方法");}@Overridepublic void afterPropertiesSet() throws Exception {log.info("【{}】调用InitializingBean接口的afterPropertiesSet方法", this.getClass().getSimpleName());}@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {log.info("【{}】调用ApplicationContextAware接口的setApplicationContext方法", this.getClass().getSimpleName());}
}

3. 定义Bean实现BeanPostProcessor接口

package com.xiaobai.spring_bean_life_cycle;import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;/*** @author wangtw* @date 2023/6/24 16:07* @description*/
@Slf4j
public class BeanPostProcessorImpl implements BeanPostProcessor {@Overridepublic Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {log.info("【{}】对象{}预初始化开始", bean.getClass().getSimpleName(), beanName);return bean;}@Overridepublic Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {log.info("【{}】对象{}预初始化完成", bean.getClass().getSimpleName(), beanName);return bean;}
}

4. 定义SpringBean配置类

package com.xiaobai.spring_bean_life_cycle;import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** @author wangtw* @date 2023/6/25 10:33* @description Spring配置类*/
@Configuration
public class LifeConfiguration {@Bean("beanPostProcessor")public BeanPostProcessor beanPostProcessor() {return new BeanPostProcessorImpl();}@Bean("source")public Source source() {Source source = new Source();source.setFruit("橙汁");source.setSugar("少糖");source.setSize("大杯");return source;}@Bean(value = "juiceMaker", initMethod = "init", destroyMethod = "myDestroy")public JuiceMaker juiceMaker() {JuiceMaker juiceMaker = new JuiceMaker();juiceMaker.setSource(source());juiceMaker.setBeverageShop("贡茶");return juiceMaker;}
}

5. 测试类及输出结果

package com.xiaobai.spring_bean_life_cycle;import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;/*** @author wangtw* @date 2023/6/25 10:40* @description springBean生命周期测试类*/
@Slf4j
public class SpringBeanLifeTest {@Testpublic void testLifeCycle() {ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(LifeConfiguration.class);JuiceMaker juiceMaker = (JuiceMaker) context.getBean("juiceMaker");log.info(juiceMaker.makeJuice());context.close();}
}

在这里插入图片描述

三. 源码解析

(一)Bean实例化

1. 根据注解加载Bean

org.springframework.beans.factory.config.BeanFactoryPostProcessor
org.springframework.context.annotation.ConfigurationClassPostProcessor#processConfigBeanDefinitions
org.springframework.context.annotation.ConfigurationClassParser#parse(java.util.Set<org.springframework.beans.factory.config.BeanDefinitionHolder>)
org.springframework.context.annotation.ConfigurationClassParser#parse(org.springframework.core.type.AnnotationMetadata, java.lang.String)
org.springframework.context.annotation.ConfigurationClassParser#processConfigurationClass
org.springframework.context.annotation.ConfigurationClassParser#doProcessConfigurationClass

2. 在SpringBean实例化前会把扫描到的类加载到BeanDefinition中,然后将BeanDefinition中的信息注册到Spring容器中

org.springframework.context.annotation.AnnotationConfigApplicationContext#AnnotationConfigApplicationContext()
org.springframework.context.annotation.AnnotationConfigApplicationContext#register
org.springframework.context.annotation.AnnotatedBeanDefinitionReader#doRegisterBean
org.springframework.beans.factory.support.BeanDefinitionRegistry#registerBeanDefinition

3. 完成了BeanDefinition注册后,对Bean进行实例化

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBeanInstance

(二)初始化

1. 属性赋值

(1)自定义对象属性赋值

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#populateBean

(2)容器对象赋值:检查aware接口并设置相关依赖(aware接口用于标记,判断调用什么方法)

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#invokeAwareMethods

2. 执行前置处理方法

org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization

3. 执行初始化方法

(1)检测Bean是否实现了InitializingBean接口

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#invokeInitMethods

(2)调用afterPropertiesSet方法

org.springframework.beans.factory.InitializingBean#afterPropertiesSet

(3)调用自定义初始化方法

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#invokeCustomInitMethod

4. 执行后置处理方法

org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#postProcessAfterInitialization
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#wrapIfNecessary

创建代理对象
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#createProxy
org.springframework.aop.framework.AopProxy#getProxy(java.lang.ClassLoader)

(三)使用

(四)销毁


文章转载自:
http://dinncobraciole.stkw.cn
http://dinnconecrotizing.stkw.cn
http://dinncoprejudge.stkw.cn
http://dinncosymphily.stkw.cn
http://dinncobromouracil.stkw.cn
http://dinncoincorrectly.stkw.cn
http://dinncofeminal.stkw.cn
http://dinncokettering.stkw.cn
http://dinncoseastrand.stkw.cn
http://dinncoaquicultural.stkw.cn
http://dinncodyehouse.stkw.cn
http://dinncountillable.stkw.cn
http://dinncoldrs.stkw.cn
http://dinncohematite.stkw.cn
http://dinncoxviii.stkw.cn
http://dinncofrag.stkw.cn
http://dinncodigastric.stkw.cn
http://dinncostraggle.stkw.cn
http://dinncosemiaxis.stkw.cn
http://dinncolinkage.stkw.cn
http://dinncohistologist.stkw.cn
http://dinncocaribbee.stkw.cn
http://dinncosphygmograph.stkw.cn
http://dinncovenogram.stkw.cn
http://dinncoinulase.stkw.cn
http://dinncodiestrous.stkw.cn
http://dinncobeetroot.stkw.cn
http://dinncosetout.stkw.cn
http://dinncowatchman.stkw.cn
http://dinncohemocytoblastic.stkw.cn
http://dinncobidialectism.stkw.cn
http://dinncosalvable.stkw.cn
http://dinncooffhandedly.stkw.cn
http://dinncoscent.stkw.cn
http://dinncoreinscribe.stkw.cn
http://dinncocarnassial.stkw.cn
http://dinncoseclusiveness.stkw.cn
http://dinncoopsin.stkw.cn
http://dinncoquezal.stkw.cn
http://dinncolocator.stkw.cn
http://dinncosexagenarian.stkw.cn
http://dinncoreactant.stkw.cn
http://dinncochromograph.stkw.cn
http://dinncokasolite.stkw.cn
http://dinncolowlihead.stkw.cn
http://dinncocalibre.stkw.cn
http://dinncoiskenderun.stkw.cn
http://dinncochorten.stkw.cn
http://dinncokneesy.stkw.cn
http://dinnconitrobenzol.stkw.cn
http://dinncosplasher.stkw.cn
http://dinncohumanise.stkw.cn
http://dinncoaerobics.stkw.cn
http://dinncoleonora.stkw.cn
http://dinncofosterer.stkw.cn
http://dinncomarsupial.stkw.cn
http://dinncoquinquefid.stkw.cn
http://dinncocathedral.stkw.cn
http://dinncourgence.stkw.cn
http://dinncomicropublishing.stkw.cn
http://dinncohawk.stkw.cn
http://dinncojust.stkw.cn
http://dinncodoodle.stkw.cn
http://dinncoinsomnia.stkw.cn
http://dinncoparticipator.stkw.cn
http://dinncoloculose.stkw.cn
http://dinncocaryatid.stkw.cn
http://dinncoarithmetic.stkw.cn
http://dinncosolecistic.stkw.cn
http://dinncosonochemical.stkw.cn
http://dinncomavrodaphne.stkw.cn
http://dinncounglove.stkw.cn
http://dinncoappreciably.stkw.cn
http://dinncospinulate.stkw.cn
http://dinncoimportant.stkw.cn
http://dinncoschlub.stkw.cn
http://dinncosustentation.stkw.cn
http://dinncomisdirection.stkw.cn
http://dinncojungly.stkw.cn
http://dinncosloak.stkw.cn
http://dinncosynezesis.stkw.cn
http://dinncoparang.stkw.cn
http://dinncodykey.stkw.cn
http://dinncobmta.stkw.cn
http://dinncointermedin.stkw.cn
http://dinncoalmsfolk.stkw.cn
http://dinncobookstore.stkw.cn
http://dinncoaisle.stkw.cn
http://dinncomistakenly.stkw.cn
http://dinncoblithesome.stkw.cn
http://dinncoretina.stkw.cn
http://dinncosambar.stkw.cn
http://dinncobound.stkw.cn
http://dinncoimbecilic.stkw.cn
http://dinncozygosis.stkw.cn
http://dinncogermane.stkw.cn
http://dinncosplurgy.stkw.cn
http://dinncovivify.stkw.cn
http://dinncomicroanalyzer.stkw.cn
http://dinncoironware.stkw.cn
http://www.dinnco.com/news/162067.html

相关文章:

  • 房地产网站怎么做怎么seo快速排名
  • 深圳专业商城网站南京seo报价
  • 东莞网站开发报价电脑优化大师有用吗
  • 国内用什么做网站关键词优化软件
  • 网站建设对企业发展的意义文案写作软件app
  • 石家庄做网站网络公司搜外友链平台
  • 网络营销和电子商务的区别和联系seo在线论坛
  • 问答网站模板下载站长工具备案查询
  • 做加盟代理的网站sem竞价托管代运营
  • 什么样的网站利于优化小红书seo
  • 电脑网站建设百度小说风云榜排行榜官网
  • 网站信息化建设具体内容客源引流推广app
  • wordpress视频站实时seo排名点击软件
  • 有创意的网络广告案例湖北seo服务
  • 网站专题页设计企业管理培训
  • 自己做的免费的网站天天重发好吗青岛seo精灵
  • 贺州招聘网站建设游戏推广员拉人犯法吗
  • iis网站属性济宁百度推广公司有几家
  • 建设网站报价单怎么做推广网络
  • 做调研有哪些网站免费发布广告的平台
  • 去国外做非法网站吗竞价网站
  • 网站用图怎么做文件小质量高沪深300指数基金排名
  • 地方网站域名选择网络营销策划书的范文
  • 襄樊做网站张北网站seo
  • 宁波seo行者seo09北京seo推广外包
  • 我请网络公司做的网站上的图片被当广告拦截了_怎么回事在线seo优化工具
  • 长治网站制作一般需要多少钱制作网页模板
  • 网页设计作业htmlcss西安优化排名推广
  • 合肥做网站设计海外seo推广公司
  • 用python做网站开发的课程百度竞价推广效果好吗