Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between singleton and application scope pattern in spring?

As per spring documentaion:-

This is somewhat similar to a Spring singleton bean but differs in two important ways: It is a singleton per ServletContext, not per Spring 'ApplicationContext' (or which there may be several in any given web application), and it is actually exposed and therefore visible as a ServletContext attribute.

But I am not able to get the above..

like image 226
Yatin Garg Avatar asked Apr 26 '26 05:04

Yatin Garg


1 Answers

The ServletContext is provided by you application server (e.g. tomcat), while you can define multiple Spring Context (application context) for your web application: http://alvinalexander.com/blog/post/java/how-load-multiple-spring-context-files-web-application

But for practical purposes this can neglected. The more interesting fact is that the bean is exposed/visible through the ServletContext: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-scopes-application

like image 150
hotzst Avatar answered Apr 28 '26 03:04

hotzst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!