Monday, March 23, 2015

Spring IOC Interview Questions (Experience

  1. What would happen if we have a prototype bean injected into a singleton bean ? How many objects of prototype bean object will be created ? 
    When a singleton bean is created , a single instance of the prototype bean objecte is created. It won't create a new prototype bean.
  2. Are singleton beans in Spring a regular singleton object ?
  3. Are Singleton beans thread safe ?
  4. A bean can be marked abstract by abstract=true, does not that mean we have to make the corresponding java class abstract ? 
    No, a bean marked abstract makes the bean not instanciatable, also it makes an ideal situation to use this reference as parent to other child bean definition. Making the corresponding java as abstract is not necessary but can be done
  5. If an inner bean is defined with an id, can you use this id to fetch the bean from the container ?
    No, An bean defined inner bean can't be accessed even if the id attribute has value. so getBean("theInnerId") will fail with NoSuchBeanDefinitionException.
  6. What is the implementation of List is used when you use the tag in a bean definition ?
  7. How do you use a particular implementation of collection in your bean definition ? 
    You can use the and with set-class to the implementation you want to use.For example to use linkedList as implementation, and don't forget to include the schema details in the beans tag. Also util tag can let you create id of the collection , thus this can be refered or shared with any other beans by using the regular way , ie the ref tag.

No comments:

Post a Comment