简体   繁体   English

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

[英]Lifetime of object created using ApplicationContext.xml in Spring MVC

I am new to spring application... 我是春季申请的新手......

I want to know, When the object created using applicationcontext.xml file will get destroyed?.. 我想知道,当使用applicationcontext.xml文件创建的对象会被销毁?

ie, I want to know the life time of the object created by applicationcontext.xml file... 即,我想知道applicationcontext.xml文件创建的对象的生命周期...

I tried a lot in Google search but I can't able to find out solution.. All suggestions are towards the Scope of bean.. Is that scope determines the lifetime? 我在谷歌搜索中尝试了很多,但我无法找到解决方案..所有建议都是针对bean的范围。这个范围是否决定了生命周期?

How to find out lifetime of object and when ll it get destroyed in Spring MVC?... 如何找出对象的生命周期以及什么时候它会在Spring MVC中被销毁?...

Thanks in advance and expects to get resolve soon... Please help me out.. 在此先感谢,并希望尽快得到解决...请帮帮我..

Spring will destroy the objects (only Singletons) when the applicationContext is closed. 当applicationContext关闭时,Spring将销毁对象(仅限单例)。

From Doc 来自Doc

A BeanFactory is supposed to invoke the destroy method if it disposes a cached singleton. 如果BeanFactory处理缓存的单例,则应该调用destroy方法。 An application context is supposed to dispose all of its singletons on close. 应用程序上下文应该关闭所有单例。

Comment from Spring Team member 来自Spring Team成员的评论

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. 需要注意的一点是,Spring不跟踪原型/范围的bean - 它只跟踪单例,因此,destroy方法只会在单例上调用

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

Yes scope determines the lifetime. 是范围决定了生命周期。 Look at the different bean scopes available 查看可用的不同bean范围

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM