Spring IOC container will create only one object of the Test class. If....
We have two scopes for simple beans :
- singleton
- prototype
If it is a web application then we have 3 scopes :
- request
- session
- context
So what IOC internally is doing after reading XML file document:
Whenever we try to call getBean of “test” it will try to search for references and if it will find “test” that “test” reference class object it will create and if its scope is singleton then it will create singleton test and you know what it is.
I we call it multiple time the same object will be return.
But if scope is prototype then it will create new object for every call.. ;)
So this is how we creates objects of pojo classes. We have created objects by using core container.
Advanced container :
ApplicationContext ap = new ClassPathXMLApplicationContext(“spring.xml”);
ap.getBean(“test”);
ap.getBean(“test”);
No comments:
Post a Comment