D.M.C. 2022-04-26 02:06 采纳率: 0%
浏览 19

关于Scope=prototyp的设置下,close没有显示销毁

刚发现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.

    评论

报告相同问题?

问题事件

  • 创建了问题 4月26日