Injection in Spring

  1. How many ways can one inject source bean into target by using Spring ?
    There are two ways how you can inject source bean into the target bean. Constructor injection and setter inject.
  2. What is the difference between Constructor injection and setter injection ?
          Constructor injection                                                     Setter Injection
    1. Happens on the constructor of the bean                   Happens in the setter method / mutator method in the bean
    2. <constructor-arg> tag is used in the xml definition     <property> tag is used
    3. Use this for all mandatory fields                                Use this for all optional fields
    4. Less verbose , but looks bad if you have a lot of       More verbose, but gives access to the fields even after the bean is constructed.
      composed objects, for examle if your constructor
      takes a lot of argument this can be a bad idea for
      readability 
  3. Can Spring inject existing Java classes into a target bean ?
    Yes, Spring can inject existing Java classes into the target bean, for example you use <property name="pincode" value="343222" /> , here the value 343222 is a string, you can mention the type of the bean by mentioning type="java.lang.String" as well.
  4. Does the order in which the declaration of bean matter ?

  5. What is lazy loading of  beans?
  6. What is p namespace ?
  7. What is automatic name-by-class behavior ?
  8. What is top level and inner anonymous bean ?
  9. Can a Bean have more than one name  ?
  10.