admin管理员组文章数量:1642680
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
本文标签: ApplicationListener
版权声明:本文标题:ApplicationListener 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1726219698a1060954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论