在以前使用spring mvc的时候,在复杂的下单和支付中有一部分功能使用的Spring事件驱动模型去完成!具体优势不啰嗦了,发现涛哥有篇文章讲得比较详细:详解Spring事件驱动模型java
最初准备基于Guava 的Eventbus去实现,发现其并不太适合!如下来自官方的wikigit
Why must I create my own Event Bus, rather than using a singleton? EventBus doesn't specify how you use it; there's nothing stopping your application from having separate EventBus instances for each component, or using separate instances to separate events by context or topic. This also makes it trivial to set up and tear down EventBus objects in your tests.github
Of course, if you'd like to have a process-wide EventBus singleton, there's nothing stopping you from doing it that way. Simply have your container (such as Guice) create the EventBus as a singleton at global scope (or stash it in a static field, if you're into that sort of thing).spring
In short, EventBus is not a singleton because we'd rather not make that decision for you. Use it how you like.mvc
JFinal-event
实现得比较简单,整个代码结构如图: app
其核心原理是,使用guava
Multimap
转载全部的监听器和监听器监听的泛型ApplicationEvent
的子类!ide
http://git.oschina.net/596392912/JFinal-eventui
欢迎拍砖~.~
google
https://github.com/google/guava/tree/master/guava/src/com/google/common/eventbus.net