This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Can someone please explain my question according to following paragraph in "Spring in action"
"another 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".
1:What is the difference between bean "loading" and bean "initialisation" or "creation"?
2:If we want to access a bean using the ApplicationContext,then do we need to use following code:
or the beans are automatically created without the above line.
Similarly ,is it necessary to give the following code in case of BeanFactory:
I recommend using the latest version of Spring in Action. You are reading an older book with older ways of doing things.
In today's Spring you do not need to know anything about the old BeanFactory. So forget about that sentence.
So, all you need to know is that Spring instantiates your objects/beans when the ApplicationContext is created. In that one line of code ApplicationContext context = new ClassPathXmlApplicationContext()
So in that one line of code, Spring is reading your configuration and then after it finishes reading all the xml, then it will instantiate all the beans in the xml and put it into a Map.
That is the default.
However, you can configure a bean to be a different scope or lazy. Which means that that one line does not instantiate the bean for you, but waits till later when you ask for it.
I personally have never set a bean to lazy because there hasn't been a use case I have come across that would require/need that.