久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

SpringBoot加載應(yīng)用事件監(jiān)聽器代碼實例

瀏覽:3日期:2023-05-14 10:58:30

利用 Spring 工廠加載機制,實例化 ApplicationListener 實現(xiàn)類,并排序?qū)ο蠹?/p>

創(chuàng)建應(yīng)用事件監(jiān)聽器

創(chuàng)建類實現(xiàn)接口ApplicationListener,可以使用@Order或?qū)崿F(xiàn)Orderd接口進行排序

@Order(Ordered.HIGHEST_PRECEDENCE)public class HelloWorldApplicationListener implements ApplicationListener<ContextRefreshedEvent> { @Override public void onApplicationEvent(ContextRefreshedEvent event) { System.out.println('HelloWorld : ' + event.getApplicationContext().getId()+ ' , timestamp : ' + event.getTimestamp()); }}

public class AfterHelloWorldApplicationListener implements ApplicationListener<ContextRefreshedEvent>,Ordered { @Override public void onApplicationEvent(ContextRefreshedEvent event) { System.out.println('AfterHelloWorld : ' + event.getApplicationContext().getId()+ ' , timestamp : ' + event.getTimestamp()); } @Override public int getOrder() { return Ordered.LOWEST_PRECEDENCE; }}

在spring.properties中配置

# ApplicationListenerorg.springframework.context.ApplicationListener=com.imooc.diveinspringboot.listener.AfterHelloWorldApplicationListener,com.imooc.diveinspringboot.listener.HelloWorldApplicationListener,

輸出

HelloWorld : application , timestamp : 1591105193644AfterHelloWorld : application , timestamp : 1591105193644

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 焦作市| 上虞市| 连江县| 通州区| 洛宁县| 涟水县| 芦溪县| 福泉市| 邻水| 沐川县| 黑河市| 德格县| 都昌县| 普宁市| 永吉县| 湘潭县| 满城县| 樟树市| 黑水县| 星座| 东明县| 布尔津县| 密山市| 新密市| 涡阳县| 东兴市| 波密县| 正宁县| 马关县| 乐山市| 南召县| 兴文县| 蚌埠市| 达日县| 镇沅| 安宁市| 毕节市| 乳山市| 凤城市| 清涧县| 清徐县|