Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype application context event listeners are not notified within the events [SPR-5248] #9922

Closed
spring-projects-issues opened this issue Oct 29, 2008 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 29, 2008

Denis Zhdanov opened SPR-5248 and commented

The IoC container only tries to manage 'singleton' beans that are IS-A org.springframework.context.ApplicationListener. So, prototype beans that are IS-A ApplicationListener are not notified within the new events. There is no reason why the container shouldn't manage prototype beans during events propagation. It's able to register the prototype bean as a listener during its instantiation. The only thing to check is to reference that beans via weak references in order to avoid memory leaks.

From the other side, expected behavior is that application text propagates new event to all of the registered listeners (prototyped beans as well). User expect that because reference documentation mentions specially only life cycle event regarding prototype beans - '3.4.2. The prototype scope':
There is one quite important thing to be aware of when deploying a bean in the prototype scope, in that the lifecycle of the bean changes slightly. Spring does not manage the complete lifecycle of a prototype bean: the container instantiates, configures, decorates and otherwise assembles a prototype object, hands it to the client and then has no further knowledge of that prototype instance. This means that while initialization lifecycle callback methods will be called on all objects regardless of scope, in the case of prototypes, any configured destruction lifecycle callbacks will not be called. It is the responsibility of the client code to clean up prototype scoped objects and release any expensive resources that the prototype bean(s) are holding onto. (One possible way to get the Spring container to release resources used by prototype-scoped beans is through the use of a custom bean post-processor which would hold a reference to the beans that need to be cleaned up.)

There was a complain about that at the spring community already - see http://forum.springframework.org/showthread.php?t=62781.


Affects: 2.5.5

Issue Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants