gpt4 book ai didi

java - 在 Spring MVC 中使用 ApplicationContext.xml 创建的对象的生命周期

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:09:49 24 4
gpt4 key购买 nike

我是 spring 应用的新手...

我想知道,当使用 applicationcontext.xml 文件创建的对象会被销毁?..

即,我想知道由 applicationcontext.xml 文件创建的对象的生命周期...

我在 Google 搜索中尝试了很多,但我无法找到解决方案。所有的建议都针对 bean 的范围。这个范围是否决定了生命周期?

如何在 Spring MVC 中找出对象的生命周期以及何时销毁它?...

在此先感谢并希望尽快得到解决......请帮助我..

最佳答案

当 applicationContext 关闭时,Spring 将销毁对象(仅 Singletons)。

来自 Doc

A BeanFactory is supposed to invoke the destroy method if it disposes a cached singleton. An application context is supposed to dispose all of its singletons on close.

Spring 团队成员的评论

One thing to note is that Spring doesn't track prototypes/scoped beans - it only tracks singletons and as a result, the destroy method will be called only on singletons.

来源:http://forum.springsource.org/showthread.php?32253-When-will-the-bean-s-destroy-method-be-invoked

关于java - 在 Spring MVC 中使用 ApplicationContext.xml 创建的对象的生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15334287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com