|
#1
|
|||
|
|||
|
Hi everyone,
I created an implementation of the ApplicationListener interface which is capable to dispatch event notifications based on annotated methods. The advantage over implementing ApplicationListener directly is similar to that of using @Controller-style MVC - you can use POJOs and you can have multiple methods with type-safe arguments rather than doing "instanceof" on a ApplicationEvent and then downcasting. The current implementation is not very optimized for speed - it scans all the methods of the target every time there is an event; this could be cached. I'm sure the forum members could think of other improvements as well. Does anybody like this enough for me to submit it as a new feature request? Sample code: Code:
public class EventListener {
@EventHandler
public void onAppEvent(MyCustomEvent event) {
// ...
}
}
Code:
<bean id="eventListener" class="EventListener"/>
<bean class="org.springframework.context.annotation.AnnotatedApplicationListener" p:target-ref="eventListener"/>
Code:
git clone http://pavel.tcholakov.net/code/eventhandler-annotation.git/ Regards, Pavel |
![]() |
| Thread Tools | |
| Display Modes | |
|
|