在spring中我们可以自定义事件,并且可以使用ApplicationContext类型对象来发布这个事件,事件发布之后,所有的ApplicaitonListener(监听器)实例都会被触发并调用指定方法onApplicationEvent()来处理.
1.定义事件:
如图所示:

2.定义监听器:
如图所示:


3.配置xml文件:
如图所示:

当事件触发时,即
ApplicationContext container = new ClassPathXmlApplicationContext(path);
container.publishEvent(new RainEvent("下雨了!"));
则所有监听该事件的监听器都会触发onApplicationEvent()方法。
相关文章:
-
2022-12-23
-
2022-12-23
-
2021-08-26
-
2021-08-13
-
2022-02-03
-
2022-01-04
-
2021-09-24
-
2022-01-27
猜你喜欢
-
2021-09-01
-
2022-12-23
-
2022-12-23
-
2021-07-24
-
2022-12-23
-
2022-12-23
-
2022-12-23
相关资源
-
下载
2021-06-05
-
下载
2022-12-28
-
下载
2022-12-22
-
下载
2021-06-24