Home
»
tutorials
»
Bean scopes in Spring Framework
June 26, 2021
Ravi Yasas
Spring Bean scopes
Set up the scope
- The @Scope annotation can be used
- There are 6 scopes are available in the application context
singleton
- This is the default scope.
- The same object is returned every time.
- Better to use for all stateless beans.
prototype
- A new object is created every time.
- Better to use for all stateful beans.
request
- Here it will create a single instance and it will available in the complete lifecycle of an HTTP request
- Only valid in ApplicationContext
session
- Here it will create a single instance and it will available in the complete lifecycle of an HTTP session
- Only valid in ApplicationContext
application
- Here it will create a single instance and it will available in the complete lifecycle of the servlet context
- Only valid in ApplicationContext
websocket
- Here it will create a single instance and it will available in the complete lifecycle of the web socket
- Only valid in ApplicationContext
0 comments :
Post a Comment