14. Dependency-on


·         One class depends on another class
·         A,B,C are 3 classes A depends on B class obj., B depends on C class obj.,
·         In this situation we use  attribute depends-on="obj" in bean class
<beans>
<bean id="a" class="bean.A" depends-on="b"></bean>
<bean id="b" class="bean.B" depends-on="c"></bean>
<bean id="c" class="bean.C"></bean>
</beans>
<!--
Here A--B & B-C
so C object will create first and then B at last A -->
Example
--------------------------------------
package bean;

public class A {
       public A() {
      
              System.out.println("A class");
       }

}
----------------------------------------------
package bean;

public class B {
       public B() {
      
              System.out.println("B class");
       }

}
----------------------------------------
package bean;

public class C {
       public C() {
      
              System.out.println("C class");
       }

}
-----------------------------------------------
package driver;
public class SpringHello {
public static void main(String[] args) {
ApplicationContext c = new ClassPathXmlApplicationContext("res/s.xml");

}
      
}
----------------------------------------------
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
<beans>
<bean id="a" class="bean.A" depends-on="b"></bean>
<bean id="b" class="bean.B" depends-on="c"></bean>
<bean id="c" class="bean.C"></bean>
</beans>
<!--
Here A--B & B-C
so C object will create first and then B at last A -->       
---------------------------------------------------------------