刚发现Scope在默认singleton单例下测试可以显示出自定义的销毁提示,但是在prototyp下就没有显示了,表示不李姐,求解释下为什么呢,可以销毁的嘛?
3条回答 默认 最新
想象之中_ 2022-04-26 02:21关注In contrast to the other scopes, Spring does not manage the complete lifecycle of a prototype bean. The container instantiates, configures, and otherwise assembles a prototype object and hands it to the client, with no further record of that prototype instance. Thus, although initialization lifecycle callback methods are called on all objects regardless of scope, in the case of prototypes, configured destruction lifecycle callbacks are not called. The client code must clean up prototype-scoped objects and release expensive resources that the prototype beans hold. To get the Spring container to release resources held by prototype-scoped beans, try using a custom bean post-processor, which holds a reference to beans that need to be cleaned up.
解决 无用评论 打赏 举报