Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
In Spring framework Singleton and prototype are two common bean scope which is available on all Spring Application Context while request, however session and global session bean scope are only available on Web aware application Context like WebApplicationContext.
Default scope is Singleton, Singleton bean scope is like Singleton pattern in Java where only one instance of bean is created per Spring container. So no matter how many times you call getBean() method, same bean instance will be returned if its bean scope is declared as Singleton. While in case of prototype bean scope, every getBean() call creates a new instance of Spring bean.
Request bean scope allows each HTTP request to have its own instance of bean created and supplied by Spring framework, while Session bean scope allows Web application to have bean instance per session basis. both of these bean scope are available on WebApplicationContext or any web aware application context. Last one which is global session bean scope is only applicable on portlet aware bean scope and allows bean instance per global session. In short Singleton vs prototype is an important which clearly segregate one instance to multiple instances of bean.