How to control object creation in Spring ?And scopes in Spring.





Spring IOC container will create only one object of the Test class. If....





We have two scopes for simple beans :

  1. singleton

  2. prototype



If it is a web application then we have 3 scopes :

  1. request

  2. session

  3. 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

Fixing yum command on linux

You may find yourself having to fix more packages. So you can just remove everything you had installed via  pip and reinstall everythin...