When will @Predestroy be called on beans prototype?

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

a) Each time the bean instance becomes unavailable (for example, ready for GC) b) When the ApplicationContext is disconnected (for example, calls close (), stop (), destroy ())

+6
source share
1 answer

Spring container will not call @PreDestroy , unlike other areas, when Spring creates an instance and configures a bean prototype, the rest depends entirely on a client that has a bean prototype, Spring does not track the bean at this point - http: //static.springsource .org / spring / docs / 3.1.x / spring-framework-reference / html / beans.html # beans-factory-scopes-prototype

+10
source

Source: https://habr.com/ru/post/924685/


All Articles