Scope of Beans in Spring Framework

Eric Anicet
5 min readNov 11, 2024

In this story, we’ll learn about the scope of Beans in the Spring Framework.

· Singleton Scope
· Prototype Scope
· Web-aware application scopes
Request scope
Session Scope
Application Scope
WebSocket Scope
· Conclusion
· References

The scope of a bean determines its lifecycle and visibility within the container. Beans can be defined to be deployed in one of several scopes. Spring Framework supports several types of bean scopes, each of which controls how and when beans are instantiated and shared across the application.

The latest version of the Spring framework defines 6 types of scopes, four of which are available only if you use a web-aware ApplicationContext.

  • singleton
  • prototype
  • request
  • session
  • application
  • websocket

Singleton Scope

The singleton is the default bean scope in the spring container.
A single instance of the class designated by this bean will be created and shared across the entire spring…

--

--

No responses yet