• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Bean getting initialised everytime, why ?

Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Emplyee interface

PermanentEmpl.java ,







now when i run MainPractise15.java, the commandline output is

now if i add attribute as follows

and if i run the main class MainPractise15.java, the output is

Now my question is why ManagerSer is initialized 3 times in first scenario and 2 times in second scenario ?
Posts: 17347
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have three beans of that type. You are also using Bean Definition inheritence in your configuration. In the first example, the parent <bean> tag get a bean instantiated as well as the other two. In your second version for the parent bean you used the attribute abstract="true", which tells Spring not to instantiate that bean, but just use the bean configuration for the other two. This is the same as creating a parent Java class as abstract or not.

public abstract class Car

public class Honda extends Car

public class Toyota extends Car

in that hierarchy I can only instantiate Honda and Toyota, not Car because it is abstract. It works the same way with <bean> tags if you have <bean abstract="true"> then Spring can't instantiate that bean.

    Bookmark Topic Watch Topic
  • New Topic