8
votes

I would like to know when will the ApplicationContext call the method annotated with @PreDestroy on a prototype-scoped bean?

a) Each time a bean instance become unreachable (eg. ready for GC) b) When the ApplicationContext is shutting down (eg. calling close(), stop(), destroy())

1

1 Answers

14
votes

Spring container will not call the @PreDestroy, unlike for other scopes once Spring instantiates, and configures the prototype bean, the rest is completely upto the client holding the prototype bean, Spring does not track the bean at that point - http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-scopes-prototype