ApplicationListener
发布日期:2021-06-28 23:30:19 浏览次数:2 分类:技术文章

本文共 1087 字,大约阅读时间需要 3 分钟。

ApplicationListener

属于Spring框架对Java中实现的监听者模式的一种框架实现,这里唯一值得着重强调的是,对于初次接触SpringBoot,但对Spring框架本身又没有过多接触的开发者来说,可能会将这个名字与SpringApplicationRunListener混淆。

如果我们要为SpringBoot应用添加自定义的ApplicationListener,有两种方式:

1)通过SpringApplication.addListeners(…)或者SpringApplication.setListeners(…)方法添加一个或者多个自定义的ApplicationListener;

2)借助SpringFactoriesLoader机制,在META-INF/spring.factories文件中添加配置(以下代码是为SpringBoot默认注册的ApplicationListener配置):

org.springframework.context.ApplicationListener=\org.springframework.boot.builder.ParentContextCloserApplicationListener,\org.springframework.boot.cloudfoundry.VcapApplicationListener,\org.springframework.boot.context.FileEncodingApplicationListener,\org.springframework.boot.context.config.AnsiOutputApplicationListener,\org.springframework.boot.context.config.ConfigFileApplicationListener,\org.springframework.boot.context.config.DelegatingApplicationListener,\org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicat-ionListener,\org.springframework.boot.logging.ClasspathLoggingApplicationListener,\org.springframework.boot.logging.LoggingApplicationListener

转载地址:https://blog.csdn.net/ynchyong/article/details/112510761 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:ApplicationContextInitializer
下一篇:SpringApplicationRunListener

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月11日 13时20分01秒