The bean defaults to Singleton.
If you do not want a singleton, the following configuration:
<bean id= "user" class= "..." singleton="false"/>
Singleton is the configuration of this bean is a singleton, if not write, is the default value of true.
Annotations:
Spring Bean life cycle
The scope of the 1.Bean can be set through the scope property of the bean tag, and the scope of the bean includes:
By default scope= "Singleton", then the Bean is a singleton, and anyone getting the bean instance is the same instance;
Scope= "Prototype", any instance is a new instance;
Scope= "Request", in a Web application, the scope of each instance is the request scope;
Scope= "Session", in a Web application, each instance is scoped to the session;
Note: By default , the bean instance is instantiated when it is initialized by the spring container, and the constructor with no arguments is called by default. In other cases, the bean will be instantiated when the instance is fetched.
2.Bean can specify the method to execute after initialization by specifying the property Init-method , and by specifying the property Destroy-method the method to execute when destroying.
Syntax: <bean. destroy-method= "method name" called when destroying "init-method=" is executed after initialization/>
Bean default configuration and life Cycle Learning Summary