Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

May 13, 2010

Spring : Difference between BeanFactory and ApplicationContext

ApplicationContext interface extends the BeanFactory interface.

A big difference between an application context and a bean factory is how
singleton beans are loaded. A bean factory lazily loads all beans, deferring bean
creation until the getBean() method is called. An application context is a bit
smarter and preloads all singleton beans upon context startup. By preloading
singleton beans, you ensure that they will be ready to use when needed—your
application won’t have to wait for them to be created.

4 comments:

shaswat said...

What is the benefit of loading singelton beans at the startup ?

If there are more singelton beans then normal beans then? more memeory will be consumed at starting

so why singelton beans are loaded at the start up in applicationcontext

Shaswat said...

What is the benefit of loading singelton beans at the startup ?

If there are more singelton beans then normal beans then? more memeory will be consumed at starting

so why singelton beans are loaded at the start up in applicationcontext

Shaswat said...

What is the benefit of loading singelton beans at the startup ?

If there are more singelton beans then normal beans then? more memeory will be consumed at starting

so why singelton beans are loaded at the start up in applicationcontext?

TarunSapra said...

@shaswat, if you have all the singleton beans preloaded, you application will be much faster, as while Autowiring dependency you wouldn't have to wait for the bean initialization. This is the reason while using spring in web applications we use ContextLoaderListener which delegates the calls to applicationContext which loads all the beans.