Spring之事件监听
2009-05-04 22:54
295 查看
Spring借助于org.springframework.context.event.ApplicationEvent抽象类及其子类实现事件的发布;借助于org.springframework.context.ApplicationListener接口及其实现者实现事件的监听。这两者构成了观察者模式(Observer)。
ApplicationContext提供了publishEvent方法,实现事件的发布。Spring提供了如下三种常见的ApplicationEvent事件实现:
org.springframework.web.context.support.RequestHandledEvent:一旦客户请求处理完毕,将发布该事件。
org.springframework.context.event.ContextRefreshedEvent:在ApplicationContext容器初始化完成或者刷新时,发布该事件。
org.springframework.context.event.ContextClosedEvent:在关闭ApplicationContext容器时,发布该事件。
为监听ApplicationEvent事件,开发者需要在目标JavaBean中实现ApplicationListener接口。
ApplicationContext提供了publishEvent方法,实现事件的发布。Spring提供了如下三种常见的ApplicationEvent事件实现:
org.springframework.web.context.support.RequestHandledEvent:一旦客户请求处理完毕,将发布该事件。
org.springframework.context.event.ContextRefreshedEvent:在ApplicationContext容器初始化完成或者刷新时,发布该事件。
org.springframework.context.event.ContextClosedEvent:在关闭ApplicationContext容器时,发布该事件。
为监听ApplicationEvent事件,开发者需要在目标JavaBean中实现ApplicationListener接口。
相关文章推荐
- Spring中的事件与监听
- Spring中使用ApplicationContext进行事件的监听之ApplicationEvent,ApplicationListener
- spring 事件监听
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
- Springboot 事件监听
- spring事件监听
- spring事件监听的功能
- 浅谈Spring-boot事件监听
- spring boot实战(第三篇)事件监听源码分析
- Spring事件源、事件监听和广播
- JavaEE开发之Spring中的事件发送与监听以及使用Profile进行环境切换
- spring boot实战(第二篇)事件监听
- Spring 通过ApplicationListener&ApplicationEvent实现事件监听
- 利用spring的ApplicationListener监听某一类事件的发生
- Spring内部的事件监听实现
- Spring 中的事件监听的实现
- Spring中使用@Async注解使Even监听事件之间的执行变为异步
- spring的事件监听机制的简化实现
- Spring架构揭秘-事件监听机制