关于java:ApplicationStartedEvent与ContextStartedEvent有区别吗

8次阅读

共计 993 个字符,预计需要花费 3 分钟才能阅读完成。

大家好,我是 DD!

明天跟大家聊聊这个问题:ApplicationStartedEvent 与 ContextStartedEvent 有区别吗?

对了,最近花了几周工夫,把 SpringForAll 社区 3.0 上线了,社区的建设指标与之前一样,心愿可能构建一个垂直于 Java 开发者的高质量技术社区!目前,曾经有靠近 1000 名注册用户,每天也有不少读者会公布一些帖子,技术气氛曾经初步造成。

如果你正在学习 Java、Spring,你能够在这里分享你的见解,碰到的问题以及帮忙他人解决问题。
前面,我会继续精选一些,我感觉有意思的问题,在这里持续给大家分享一下!

对于这个问题,其实就是 Spring 和 Spring Boot 事件机制的了解。

尽管 Spring Boot 的根底是 Spring,但 Spring Boot 并没有间接应用 Spring 中定义的罕用事件,而是从新定义了一批。

它们都是继承自 SpringApplicationEvent,而SpringApplicationEvent 继承自 ApplicationEventSpringApplicationEvent 与题主提到的 ContextStartedEvent 是平级的。

所以,Spring Boot 中应该是没用到ContextStartedEvent 的

Spring Boot 具体有哪些事件能够看看之前在 2.0 公布的时候写过一篇:[《Spring Boot 2.0 新个性(二):新增事件 ApplicationStartedEvent
》](https://blog.didispace.com/Sp…)

ApplicationStartingEvent
ApplicationEnvironmentPreparedEvent
ApplicationPreparedEvent
ApplicationStartedEvent <= 新增的事件
ApplicationReadyEvent
ApplicationFailedEvent

明天的分享就到这里!如果您学习过程中如遇艰难?能够退出咱们超高品质的 Spring 技术交换群,参加交换与探讨,更好的学习与提高!更多 Spring Boot 教程能够点击中转!,欢送珍藏与转发反对!

以上是我的意识,如果有不对的中央,也欢送评论区指出,一起学习一起进阶!

欢送关注我的公众号:程序猿 DD。第一工夫理解前沿行业音讯、分享深度技术干货、获取优质学习资源

正文完
 0