Skip to main content

Posts

Showing posts with the label Spring Bean scope

Spring Core - Bean scopes (Prototype vs Singleton)

In this post, we will discuss about various bean scopes and their differences. Bean scopes There are seven bean scopes Spring supports out of which five are only available if your ApplicationContext is web-aware. # Scope Explanation 1 singleton There will be single object of the bean per Spring IoC Container (Default). 2 prototype Scope beans to any number of object instances. Every time you get object of prototype bean from context, it will be brand new. 3 request Scope of the bean definition mapped to the lifecycle of HTTP Request. This is only available web-aware ApplicationContext . 4 session Scope of the bean definition mapped to the lifecycle of HTTP session. This is only available to web-aware ApplicationContext . 5 globalSession Scope of the bean definition mapped to the lifecycle of HTTP session usually used within Portlet context. This is only available to web-aware ApplicationContext . 6 application Scope of the bean definition mapp