日期:
来源:程序猿DD收集编辑:D叔
大家好,我是DD!
今天跟大家聊聊这个问题::ApplicationStartedEvent与ContextStartedEvent有区别吗?
关于这个问题,其实就是Spring和Spring Boot事件机制的理解。
虽然Spring Boot的基础是Spring,但Spring Boot并没有直接使用Spring中定义的常用事件,而是重新定义了一批。
它们都是继承自SpringApplicationEvent,而SpringApplicationEvent继承自ApplicationEvent,SpringApplicationEvent与题主提到的ContextStartedEvent是平级的。
所以,Spring Boot中应该是没用到ContextStartedEvent的。以上是我的认识,如果有不对的地方,欢迎评论区指出,一起学习一起进阶!
关于Spring Boot具体有哪些事件,也可以看看之前在2.0发布的时候写过一篇:《Spring Boot 2.0 新特性(二):新增事件ApplicationStartedEvent 》
ApplicationStartingEvent
ApplicationEnvironmentPreparedEvent
ApplicationPreparedEvent
ApplicationStartedEvent <= 新增的事件
ApplicationReadyEvent
ApplicationFailedEvent我们创建了一个高质量的技术交流群,与优秀的人在一起,自己也会优秀起来,赶紧点击加群,享受一起成长的快乐。另外,如果你最近想跳槽的话,年前我花了2周时间收集了一波大厂面经,节后准备跳槽的可以点击这里领取!