Reputation: 9
Are objects created at the time when the following line is executed?
ApplicationContext con = new ClassPathXmlApplicationContext("factory.xml");
or is the object obj
created at the moment the following code is executed?
Sample obj = (Sample)con.getBean("id");
Upvotes: 0
Views: 91
Reputation: 237
It depends on how the bean is defined. See this for scoping details:
If the bean is a proxy (e.g. scoped, aop) then instantiation will depend on other factors.
Upvotes: 1
Reputation: 17422
It depends on the scope of the bean, by default a bean is a singleton, and is created at the moment the first line is executed. If your bean specification has the scope "prototype", then a new bean will be created every time you execute the second line
Upvotes: 1