Spring bean destroy-method , singleton and prototype scopes

后端 未结 6 1337
暗喜
暗喜 2020-12-31 00:34

I am new to the spring framework, started with some tutorials to learn it.

I have following files,

# MainProgram.java

package test.spring;
im         


        
6条回答
  •  北海茫月
    2020-12-31 01:02

    This is the expected behaviour. There is no way for Spring to know when you have finished using a prototype scope bean, so bean destruction is not managed by Spring for prototype scoped beans. From the documentation:

    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.

    See the Spring documentation for more information.

    With regards to ApplicationContexts, you can choose the one that is best-suited to your application. It depends whether you want to use XML or annotation bean configuration, and whether or not you are running in a servlet container, for example. ApplicationContext itself is the interface at the root of the type heirarchy.

提交回复
热议问题