2

I have the ITest interface and the ClassA class:

interface ITest {}
class ClassA implements ITest {}

The XML configuration:

<bean id="objectA" class= "ClassA" />   

class Test {

       ITest objectB;

}

Although there is no bean declared in the XML file for reference objectB but it has ClassA object. Is it because it's singleton and objectA reference declared?

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
Arpan Paliwal
  • 234
  • 1
  • 7
  • 20
  • In Spring by default all bean declarations are Singleton. This works because of Spring Autowiring By Type. Do read about different ways of spring Autowiring and the order in which it is done – pvpkiran Jan 11 '18 at 13:13
  • There's nothing in your code that would trigger Spring to wire `objectA` to `Test.objectB`, so `objectB` will be `null` if you don't set it manually. – daniu Jan 11 '18 at 13:15
  • @daniu but its loading object of ClassA. – Arpan Paliwal Jan 11 '18 at 13:18

0 Answers0