Scope of the Bean
Specifies the scope of the bean element by specifying scope for the bean when the bean is configured
The default value for scope is Singleton, which is singleton mode, in one applicationcontext, each time the Getbean () method is called, the same bean is obtained.
If you want to make each fetch a different bean, you can specify that the value of scope is prototype, then each call to Getbean () will get a new bean
Scope can also go to request to refer to an HTTP request as a singleton
The session is a singleton in the entire session range.
Global-session is valid in the global scope
In spring, the singleton is confined to the ClassLoader, and the popular saying is that different classloader belong to different scopes.
Initializing and destroying beans
The initialization bean and the destroying bean have corresponding methods in the bean's life cycle, by implementing the Afterpropertiesset method of the interface Initializingbean to initialize the bean, realizing the destory of the interface Dispoablebean ( ) method to destroy the bean.
We can customize the method of initializing and destroying beans by specifying the bean's initialization and destruction methods by the Init-method property and the Destory-method property of the bean element in the configuration file. For example init-method= "init" destroy-method= "Destory", then the Inith and Destory methods must be implemented in our bean.
If all of our beans have the same method of initialization and destruction, then we can then specify the Default-init-method property and the Default-destory-method method in the beans element.
Bean's scope and bean initialization and destruction in spring