PDA

View Full Version : Non-singleton beans and application events



jpbelang
Mar 16th, 2006, 10:55 AM
When using a non singleton bean that implements the ApplicationListener interface, do ApplicationEvents get sent to all instances of the said bean ?

(I'm having a problem where only one of the beans is getting the event, and most of the examples use singletons...)

Costin Leau
Mar 18th, 2006, 05:01 PM
I haven't checked but I think if you are using prototypes then the instances already created will not receive the event mainly because Spring doesn't manage them anymore. In case of a singleton, Spring creates the instance and reuse it; there are no problems in sending events to it. However, with a prototype, a new instance is created on demand and not managed - when an event is fired, the prototypes may have been destroyed or still alive.