Spring Bean Scopes Example

While defining Spring Bean we have options to define scopes for each bean. Spring supports 5 bean scopes.

  1. singleton – This scope returns a single bean instance per Spring IoC container(Default Scope)
  2. prototype – This scope returns a new bean instance every time
  3. request – This scope returns a single bean instance for each HTTP request.
  4. session – This scope returns a single bean instance for each HTTP session.
  5. globalSession – This scope returns a single bean instance for each global HTTP session.

Last three scopes (request, session, globalSession) can be used only with web-aware ApplicationContext.

[Read more…]