在以前使用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