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

SpringBoot ApplicationEvent详解

ApplicationStartingEvent 阶段
LoggingApplicationListener#onApplicationStartingEvent
初始化日志工厂,LoggingSystemFactory接口,可以通过spring.factories进行定制
可以通过System.setProperty("org.springframework.boot.logging.LoggingSystem","类全路径限定名或者none") 指定log实现类
如果配置的是none,则返回 org.springframework.boot.logging.LoggingSystem.NoOpLoggingSystem
springboot默认指定了三种类型:
org.springframework.boot.logging.logback.LogbackLoggingSystem.Factory
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.Factory
org.springframework.boot.logging.java.JavaLoggingSystem.Factory
----------
BackgroundPreinitializer#onApplicationEvent 在当前阶段不做任何处理!!!
可以通过System.setProperty("spring.backgroundpreinitializer.ignore","true|false")
同时满足服务器是多核cpu并且非GraalVM环境
来指定是否通过后台线程去加载某些资源,默认是单独开一个线程来加载某些资源
线程名称:background-preinit 
后台加载的资源:
    ConversionServiceInitializer.class 
    ValidationInitializer.class 
    MessageConverterInitializer.class 
    JacksonInitializer.class 
    CharsetInitializer.class
有异常直接忽略
----------
DelegatingApplicationListener#onApplicationEvent 在当前阶段不做任何处理!!!
可以通过配置 context.listener.classes 属性来指定要执行的listener,是一个复合包装类
内部定义了SimpleApplicationEventMulticaster事件驱动类,用来指定配置的listener
==========
ApplicationEnvironmentPreparedEvent 阶段
EnvironmentPostProcessorApplicationListener#onApplicationEvent
onApplicationEnvironmentPreparedEvent((ApplicationEnvironmentPreparedEvent) event);
获取ConfigurableEnvironment实例
获取SpringApplication实例
通过SpringApplication实例.getResourceLoader()和ConfigurableEnvironment实例.getBootstrapContext() 获取 EnvironmentPostProcessors
所有实现了 org.springframework.boot.env.EnvironmentPostProcessor 接口的实现类,同样可以通过 spring.factories进行定制
开始遍历
1、RandomValuePropertySourceEnvironmentPostProcessor#postProcessEnvironment
将RandomValuePropertySource添加到systemEnvironment这个属性解析器集合的最后一位
RandomValuePropertySource: 用法,配置属性以random开头
比如:random.int 返回正负32位以内的一个伪随机数字
random.long 返回正负64位以内的一个伪随机数字
random.int(0,9) 包含0不包含9 中的一个伪随机数字
random.long[0,9] 包含0不包含9 中的一个伪随机数字
() 和 [] 或者 $$ 作用都一样 前后任意两个字符括起来,数字使用逗号分隔即可
2、SystemEnvironmentPropertySourceEnvironmentPostProcessor#postProcessEnvironment
判断是否设置了 SpringApplication.environmentPrefix 属性,如果设置了将systemEnvironment(SystemEnvironmentPropertySource)
的数据封装为OriginAwareSystemEnvironmentPropertySource类(SystemEnvironmentPropertySource的子类),有prefix属性.
spring.main.environment-prefix:不允许这样设置
可以通过 SpringApplicationBuilder.environmentPrefix("xx") 来设置,可以以 . - _ 等结尾,
3、SpringApplicationJsonEnvironmentPostProcessor#postProcessEnvironment
解析json属性,使用spring.application.json或者SPRING_APPLICATION_JSON命令行参数指定,按序返回有效的第一个进行解析.
解析成功后,将json属性封装为JsonPropertySource,放到servlet sources前面,如果不是servlet环境,则放在第一位
解析json属性的解析器:
org.springframework.boot.json.JsonParserFactory#getJsonParser: 指定了4种json解析器
com.fasterxml.jackson.databind.ObjectMapper
com.google.gson.Gson
org.yaml.snakeyaml.Yaml
org.springframework.boot.json.BasicJsonParser
按以上顺序进行加载,加载成功就返回对应的对象实例
4、CloudFoundryVcapEnvironmentPostProcessor#postProcessEnvironment 在springcloud环境下生效
判断是否设置了 spring.main.cloud-platform VCAP_APPLICATION VCAP_SERVICES 满足任意一个
设置了 添加 vcap sources
5、ConfigDataEnvironmentPostProcessor#postProcessEnvironment **你个**   加载并且解析设定的配置文件
spring.config.on-not-found: 配置找不到的处理方法,参考ConfigDataNotFoundAction枚举类
SpringApplication.additionalProfiles 通过 builder 构建
加载指定的配置文件并且设置environment中的profiles
# ConfigData Location Resolvers
org.springframework.boot.context.config.ConfigDataLocationResolver=\
org.springframework.boot.context.config.ConfigTreeConfigDataLocationResolver,\
org.springframework.boot.context.config.StandardConfigDataLocationResolver

# ConfigData Loaders
org.springframework.boot.context.config.ConfigDataLoader=\
org.springframework.boot.context.config.ConfigTreeConfigDataLoader,\
org.springframework.boot.context.config.StandardConfigDataLoader
6、DebugAgentEnvironmentPostProcessor#postProcessEnvironment
reactor.tools.agent.ReactorDebugAgent有这个类并且spring.reactor.debug-agent.enabled属性配置为true时
执行 ReactorDebugAgent init() 方法
7、IntegrationPropertiesEnvironmentPostProcessor#postProcessEnvironment
META-INF/spring.integration.properties 这个文件存在时加载内容并且转化为IntegrationPropertiesPropertySource添加到sources结尾
----------
AnsiOutputApplicationListener#onApplicationEvent
进行属性绑定 spring.output.ansi.enabled org.springframework.boot.ansi.AnsiOutput#enabled 参考 Enabled 枚举类
spring.output.ansi.console-available  AnsiOutput.consoleAvailable = consoleAvailable
----------
LoggingApplicationListener#onApplicationEvent
日志文件和属性初始化配置
----------
BackgroundPreinitializer#onApplicationEvent
可以通过System.setProperty("spring.backgroundpreinitializer.ignore","true|false")
同时满足服务器是多核cpu并且非GraalVM环境
来指定是否通过后台线程去加载某些资源,默认是单独开一个线程来加载某些资源
线程名称:background-preinit 
后台加载的资源:
    ConversionServiceInitializer.class 
    ValidationInitializer.class 
    MessageConverterInitializer.class 
    JacksonInitializer.class 
    CharsetInitializer.class
有异常直接忽略
----------
DelegatingApplicationListener#onApplicationEvent
可以通过配置 context.listener.classes 属性来指定要执行的listener,是一个复合包装类
内部定义了SimpleApplicationEventMulticaster事件驱动类,用来指定配置的listener
----------
FileEncodingApplicationListener#onApplicationEvent1
spring.mandatory-file-encoding: 查看是否配置了此属性,强制编码,如果这个与file.encoding不符合报错!!!
==========
bindToSpringApplication(environment) // 将spring.main开头的属性配置绑定到SpringApplication属性上
==========
applyInitializers(context); // 执行ApplicationContextInitializer接口的实现类
==========
ApplicationContextInitializedEvent
BackgroundPreinitializer#onApplicationEvent 此阶段啥也不做!!!
----------
DelegatingApplicationListener#onApplicationEvent 此阶段啥也不做!!!
==========
ApplicationPreparedEvent
EnvironmentPostProcessorApplicationListener#onApplicationEvent
onApplicationPreparedEvent() > EnvironmentPostProcessorApplicationListener#finish() > DeferredLogs#switchOverAll()
打印日志 
----------
LoggingApplicationListener#onApplicationEvent
注册springBootLoggingSystem单例Bean
logFile存在并且springBootLogFile不存在这个Bean时注册springBootLogFile单例Bean
loggerGroups存在并且springBootLoggerGroups不存在这个Bean时注册springBootLoggerGroups单例Bean
springBootLoggingLifecycle单例Bean不存在BeanFactory.getParent为空时注册springBootLoggingLifecycle单例Bean
----------
BackgroundPreinitializer#onApplicationEvent 此阶段啥也不做!!!
----------
DelegatingApplicationListener#onApplicationEvent 此阶段啥也不做!!!
==========
中间存在的各种事件驱动类
ServletWebServerInitializedEvent
SpringApplicationAdminMXBeanRegistrar#onApplicationEvent : onWebServerInitializedEvent((WebServerInitializedEvent) event);
DelegatingApplicationListener#onApplicationEvent 此阶段啥也不做!!!
ServerPortInfoApplicationContextInitializer#onApplicationEvent : 绑定server.ports sources
----------
ContextRefreshedEvent
DelegatingApplicationListener#onApplicationEvent 此阶段啥也不做!!!
ConditionEvaluationReportLoggingListener.ConditionEvaluationReportListener#onApplicationEvent 打印方法 ConditionEvaluationReportMessage
ClearCachesApplicationListener#onApplicationEvent 清理加载反射field和method的缓存数据,调用类加载器的clearCache方法清理缓存
SharedMetadataReaderFactoryContextInitializer.SharedMetadataReaderFactoryBean#onApplicationEvent 清理加载的class缓存数据
ResourceUrlProvider#onApplicationEvent 静态资源 /webjars/** 和 /static/**
==========
ApplicationStartedEvent
BackgroundPreinitializer#onApplicationEvent 此阶段啥也不做!!!
----------
DelegatingApplicationListener#onApplicationEvent 此阶段啥也不做!!!
----------
StartupTimeMetricsListener#onApplicationEvent
设置埋点监控 TimeGauge
----------
TomcatMetricsBinder#onApplicationEvent
设置tomcat监控绑定
----------
AvailabilityChangeEvent
DelegatingApplicationListener#onApplicationEvent 此阶段啥也不做!!!
----------
ApplicationAvailabilityBean#onApplicationEvent 添加到 org.springframework.boot.availability.ApplicationAvailabilityBean#events 集合中 应用启动好了
==========
ApplicationReadyEvent
SpringApplicationAdminMXBeanRegistrar#onApplicationEvent 应用准备好了
----------
BackgroundPreinitializer#onApplicationEvent 此阶段啥也不做!!!
----------
StartupTimeMetricsListener#onApplicationEvent  注册TimeGauge埋点监控
----------
DelegatingApplicationListener#onApplicationEvent 此阶段啥也不做!!!
==========
AvailabilityChangeEvent
ApplicationAvailabilityBean#onApplicationEvent 添加到 org.springframework.boot.availability.ApplicationAvailabilityBean#events 集合中 应用准备好了
 

相关文章:

SpringBoot ApplicationEvent详解

ApplicationStartingEvent 阶段 LoggingApplicationListener#onApplicationStartingEvent 初始化日志工厂,LoggingSystemFactory接口,可以通过spring.factories进行定制 可以通过System.setProperty("org.springframework.boot.logging.LoggingSystem",&q…...

WebSocket 报java.io.IOException: 远程主机强迫关闭了一个现有的连接。

在客户端强制关闭时,或者窗口强制关闭时,后端session没有关闭。 有时还会报:java.io.EOFException: 这个异常 前端心跳没有收到信息,还在心跳。 CloseReason close new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, &…...

关于git约定式提交IDEA

背景 因为git提交的消息不规范导致被乱喷,所以领导统一规定了约定式提交 官话 约定式提交官网地址 约定式提交规范是一种基于提交信息的轻量级约定。 它提供了一组简单规则来创建清晰的提交历史; 这更有利于编写自动化工具。 通过在提交信息中描述功能…...

【计算机网络】http协议

目录 前言 认识URL URLEncode和URLDecode http协议格式 http方法 GET POST GET与POST的区别 http状态码 http常见header 简易的http服务器 前言 我们在序列化和反序列化这一章中,实现了一个网络版的计算器。这个里面设计到了对协议的分析与处…...

仓库太大,clone 后,git pull 老分支成功,最新分支失败

由于 git 仓库太大,新加入的小伙伴在拉取时,无法切换到最新的分支,报错如下: fetch-pack: unexpected disconnect while reading sideband packet fatal: early EOF fatal: fetch-pack: invalid index-pack output在此记录解决步…...

javafx Dialog无法关闭

// 生成二维码图片String qrCodeText "https://example.com";DialogPane grid new DialogPane();grid.setPadding(new Insets(5));VBox vBox new VBox();vBox.setAlignment(Pos.CENTER);Image qrCodeImage generateQRCodeImage(qrCodeText);ImageView customImag…...

vue3中TCplayer应用

环境win10:vitevue3elementUI 1 安装 npm install tcplayer.js2 使用 <template><div><video id"player-container-id" width"414" height"270" preload"auto" playsinline webkit-playsinline></video>&l…...

算法通关村14关 | 数据流中位数问题

1. 数据流中位数问题 题目 LeetCode295: 中位数是有序列表中间的数&#xff0c;如果列表长度是偶数&#xff0c;中位数是中间两个数的平均值&#xff0c; 例如:[2,3,4]的中位数是3&#xff0c; [2,3]中位数是&#xff08;23&#xff09;/ 2 2.5 设计一个数据结构&#xff1a; …...

工厂模式 与 抽象工厂模式 的区别

工厂模式&#xff1a; // 抽象产品接口 interface Product {void showInfo(); }// 具体产品A class ConcreteProductA implements Product {Overridepublic void showInfo() {System.out.println("This is Product A");} }// 具体产品B class ConcreteProductB impl…...

安装虚拟机+安装/删除镜像

安装虚拟机 注意&#xff0c;官网可能无法登录&#xff0c;导致无法从官网下载&#xff0c;就自己去网上搜靠谱的下载&#xff0c;我用的16.2.3 删除镜像 Vm虚拟机怎么删除已经创建的系统&#xff1f;Vm虚拟机创建好之后iso删除方法 - 系统之家 (xitongzhijia.net) 安装镜像…...

MySQL的内置函数复合查询内外连接

文章目录 内置函数时间函数字符串函数数学函数其他函数 复合查询多表笛卡尔积自连接在where中使用子查询多列子查询在from中使用子查询 内连接外连接左外连接右外连接 内置函数 时间函数 函数描述current_date()当前日期current_time()当前时间current_timestamp()当前时间戳…...

操作系统(OS)与系统进程

操作系统&#xff08;OS&#xff09;与系统进程 冯诺依曼体系结构操作系统(Operator System)进程基本概念进程的描述&#xff08;PCB&#xff09;查看进程通过系统调用获取进程标示符&#xff08;PID&#xff09;通过系统调用创建进程&#xff08;fork&#xff09;进程状态&…...

防重复提交:自定义注解 + 拦截器(HandlerInterceptor)

防重复提交&#xff1a;自定义注解 拦截器&#xff08;HandlerInterceptor&#xff09; 一、思路&#xff1a; 1、首先自定义注解&#xff1b; 2、创建拦截器实现类&#xff08;自定义类名称&#xff09;&#xff0c;拦截器&#xff08;HandlerInterceptor&#xff09;; 3…...

Excel中将文本格式的数值转换为数字

在使用excel时&#xff0c;有时需要对数字列进行各种计算&#xff0c;比如求平均值&#xff0c;我们都知道应该使用AVERAGE()函数&#xff0c;但是很多时候结果却“不尽如人意”。 1 问题&#xff1a; 使用AVERAGE函数&#xff1a; 结果&#xff1a; 可以看到单元格左上角有个…...

uni-app开发小程序中遇到的map地图的点聚合以及polygon划分区域问题

写一篇文章来记录以下我在开发小程序地图过程中遇到的两个小坑吧&#xff0c;一个是点聚合&#xff0c;用的是joinCluster这个指令&#xff0c;另一个是polygon在地图上划分多边形的问题&#xff1a; 1.首先说一下点聚合问题&#xff0c;由于之前没有做过小程序地图问题&#…...

【笔记】软件测试的艺术

软件测试的心理学和经济学 测试是为发现错误而执行程序的过程&#xff0c;所以它是一个破坏性的过程&#xff0c;测试是一个“施虐”的过程。 软件测试的10大原则 1、测试用例需要对预期输出的结果有明确的定义 做这件事的前提是能够提前知晓需求和效果图&#xff0c;如果不…...

配置本地maven

安装maven安装包 修改环境变量 vim ~/.bash_profile export JMETER_HOME/Users/yyyyjinying/apache-jmeter-5.4.1 export GOROOT/usr/local/go export GOPATH/Users/yyyyjinying/demo-file/git/backend/go export GROOVY_HOME/Users/yyyyjinying/sortware/groovy-4.0.14 exp…...

C# 按钮的AcceptButton和CancelButton属性

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System...

SMT贴片制造:专业、现代、智能的未来之选

在现代科技的快速发展下&#xff0c;SMT贴片制造作为电子元器件的核心工艺之一&#xff0c;正以其专业、现代和智能的特点成为未来的首选。 随着电子产品越来越小型化&#xff0c;传统的手工焊接已经无法满足高速、高精度、高稳定性的要求。而SMT贴片制造作为一种先进的表面贴…...

python sqlalchemy db.session 的commit()和colse()对session中的对象的影响

实验一&#xff1a;commit&#xff08;&#xff09;之后查看stu的属性id,查看db.session是否改变 db_test.route("/db_test",methods["GET"]) def db_test():stuStuTest()stu.stu_age22stu.stu_name"nnannns"stu.stu_class11print("sessio…...

python读取图像小工具

一、和图像交互获得图像的坐标和像素值 import cv2 import numpy as np import signal import threading import timeif __name__ __main__:img cv2.imread(XXX,0)#读取图片font_face,font_scale,thicknesscv2.FONT_HERSHEY_SIMPLEX,0.5,1#鼠标交互def mouseHandler(event,x…...

【ES6】JavaScript中Reflect

Reflect是JavaScript中的一个内建对象&#xff0c;它提供了一组方法&#xff0c;用于对对象和函数进行操作和检查。这些方法与内建对象的方法非常相似&#xff0c;但具有更高的灵活性。 以下是Reflect对象的一些常用方法&#xff1a; 1、Reflect.apply(target, thisArgument,…...

Ajax + Promise复习简单小结simple

axios使用 先看看老朋友 axios axios是基于Ajaxpromise封装的 看一下他的简单使用 安装&#xff1a;npm install axios --save 引入&#xff1a;import axios from axios GitHub地址 基本使用 axios({url: http://hmajax.itheima.net/api/province}).then(function (result…...

WebDAV之π-Disk派盘 + 小书匠

小书匠是一款功能丰富,强大的知识管理工具。全平台覆盖,离线数据存储,自定义数据服务器,所见即所得的 markdown 编辑体验。 小书匠提供了多种实用的编辑模式,例如:栏编辑、双栏编辑、三栏编辑、全屏写作、全屏阅读等。并且该软件还提供了许多有用的扩展语法,比如Latex公…...

LTE ATTACH流程、PDN流程、PGW地址分配介绍

1、S-GW\P-GW选择 MME根据S-GW和P-GW的拓扑信息进行S-GW/P-GW的选择&#xff0c;在S-GW的候选序列和P-GW的候选序列中比较&#xff0c;寻找是否有合一的S-GW/P-GW&#xff0c;并且根据S-GW的优先级和权重信息进行排序&#xff0c;得到S-GW/P-GW的候选组。 2、SGW>PGW连接 PD…...

SQL sever中用户管理

目录 一、用户管理常见方法 二、用户管理方法示例 2.1. 创建登录账户&#xff1a; 2.1.1 检查是否创建账户成功&#xff1a; 2.2. 创建数据库用户&#xff1a; 2.2.1检查用户是否创建成功&#xff1a; 2.3. 授予权限&#xff1a; 2.3.1授予 SELECT、INSERT 和 U…...

linux————pxe网络批量装机

目录 一、概述 什么是pxe pxe组件 二、搭建交互式pxe装机 一、配置基础环境 二、配置vsftpd 三、配置tftp 四、准备pxelinx.0文件、引导文件、内核文件 一、准备pxelinux.0 二、准备引导文件、内核文件 五、配置dhcp 一、安装dhcp 二、配置dhcp 六、创建default文…...

处理时延降低24倍,联通云粒数据引擎优化实践

*作者&#xff1a;郑扬勇&#xff0c;云粒星河数据中台产品负责人 云粒智慧科技有限公司成立于 2018 年 6 月&#xff0c;是中国联通集团混改以来成立的首家合资公司&#xff0c;是中国智慧城市数智化建设者。一直以来&#xff0c;云粒智慧以数字化、智能化、集约化产品为核心&…...

学习MATLAB

今日&#xff0c;在大学慕课上找了一门关于MATLAB学习的网课&#xff0c;MATLAB对于我们这种自动化的学生应该是很重要的&#xff0c;之前也是在大三的寒假做自控的课程设计时候用到过&#xff0c;画一些奈奎斯特图&#xff0c;根轨迹图以及伯德图&#xff0c;但那之后也就没怎…...

React 18 对 state 进行保留和重置

参考文章 对 state 进行保留和重置 各个组件的 state 是各自独立的。根据组件在 UI 树中的位置&#xff0c;React 可以跟踪哪些 state 属于哪个组件。可以控制在重新渲染过程中何时对 state 进行保留和重置。 UI 树 浏览器使用许多树形结构来为 UI 建立模型。DOM 用于表示 …...

成都建设银行官方网站/百度问答平台

http://codeforces.com/problemset/problem/1213/E 题目大意&#xff1a;给两个字符串SSS和TTT&#xff0c;它们的长度均为222&#xff0c;且只包含字符a,b,ca,b,ca,b,c。对于给定的nnn&#xff0c;问能否找到一个长为3∗n3*n3∗n的字符串resresres&#xff0c;使得resresres恰…...

wordpress 最简单皮肤/哪个搜索引擎能搜敏感内容

问题起因 近日做的一个项目&#xff0c;我们提供jar包给其它开发方做开发&#xff0c;用户调用jar包里的一个功能&#xff0c;该功能执行后写了数据库。客户需要在该该功能执行完后能得到通知&#xff0c;这客户可以去数据库中取新的刷新后的数据。 什么是回调 java中一个类&…...

个人网站能 做淘客吗/怎么自己创建网站

进大厂本来就很难了&#xff0c;不过做足了准备&#xff0c;你会发现很多问题都迎刃而解了&#xff0c;当然有时候运气也占了一部分&#xff0c;除了运气以外&#xff0c;当然与我自身的努力也是分不开的。运气也是实力的一部分&#xff0c;毕竟天助自助者~ 每次到年底做总结的…...

广州网站维护/产品网络营销策划方案

给定一个长度为n的数组a&#xff0c;它有n(n1)/2​​个子数组。请计算这些子数组的和&#xff0c;然后按照升序排列&#xff0c;并返回排序后第k个数。1≤n≤10​^51≤a​i≤10^​91≤k≤​n(n1)/2在线评测地址&#xff1a;LintCode 领扣Example1Input: [2,3,1,4] 6 Output:5 …...

云主机如何做两个网站/百度seo排名教程

网页爬虫知识点总结 1.什么是爬虫&#xff1f; 爬虫就是&#xff1a;模拟浏览器发送请求&#xff0c;获取响应2.爬虫的分类&#xff0c;爬虫的流程 聚焦爬虫&#xff1a;针对特定的网站的爬虫 准备url地址 -->发送请求 获取响应–> 提取数据–> 保存获取响应–>…...

工信部网站登陆/市场seo是什么

自定义一个ViewGroup的首要任务就是要定义测量逻辑&#xff0c;让ViewGroup知道自己的大小&#xff0c;才能在屏幕上展示出来。 根据上面的分析得出&#xff1a; 当图片只有一张的时候&#xff0c;整个ViewGroup的大小和负责显示图片的ImageView是一样大的。这个大小可以根据图…...