Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Core Container

Reply
 
Thread Tools Display Modes
  #1  
Old Apr 8th, 2009, 07:53 AM
kay kay is offline
Member
 
Join Date: Aug 2004
Posts: 65
Default Annotation-based support for ApplicationListeners

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) {
        // ...
    }
}
Configuration:

Code:
    <bean id="eventListener" class="EventListener"/>
    <bean class="org.springframework.context.annotation.AnnotatedApplicationListener" p:target-ref="eventListener"/>
A Maven project that includes an integration test can be checked out with Git:

Code:
git clone http://pavel.tcholakov.net/code/eventhandler-annotation.git/
Or just grab the zip from http://pavel.tcholakov.net/code/even...n-20090408.zip

Regards,
Pavel
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:12 PM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.