What bean scopes does Spring support? Explain them.

Technology CommunityCategory: SpringWhat bean scopes does Spring support? Explain them.
VietMX Staff asked 3 years ago

The Spring Framework supports following five scopes, three of which are available only if you use a web-aware ApplicationContext.

  • singleton − This scopes the bean definition to a single instance per Spring IoC container.
  • prototype − This scopes a single bean definition to have any number of object instances.
  • request − This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
  • session − This scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.
  • global-session − This scopes a bean definition to a global HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.