In spring, there are five types of beans in scope: The default is singleton mode,
Singleton
Prototype
Request
Session
Global session
When configuring scopes, using the Scope property, the XML file is configured as follows
To view the official spring documentation, explain the following:
1, Singleton
If a bean is configured as Singelton, it indicates that the bean has only one instance in the spring IOC container, that is, a singleton
The configuration is as follows: The following two configurations are the same, using singleton by default
You can create a new spring project for testing: Observe whether the return is true or false
2, prototype
Prototype-scoped Bean, each request produces a new Bean instance, equivalent to the operation of
For a new instance of prototype, the spring container does not perform his life cycle callback method and can refer to the Spring life cycle document I wrote.
The Spring official documentation explains the following
3. Request, session, and global session scopes these three scopes are mainly used in the Web,
Request: Indicates that a new bean will be generated for each HTTP request, and that the bean is valid only within the current HTTP requests
Session: Indicates that a new bean will be generated for each HTTP request, and that the bean is valid only within the current HTTP session
Global session: Indicates that a new bean will be generated for each HTTP request, but it only makes sense in a portlet-based web application
Spring's scope scope