Tim Cooke wrote:What was your answer to the question? What was your reasoning?
I answered him I can autowire this normally as I do usually. No special case in this. For example:
public interface Interface {
public void print();
}
------------------------------
public class Country implements Interface{
public
String country_Name;
Capital captial;
public String getCountry_Name() {
return country_Name;
}
public void setCountry_Name(String country_Name) {
this.country_Name = country_Name;
}
public Capital getCaptial() {
return captial;
}
public void setCaptial(Capital captial) {
this.captial = captial;
}
@Override
public void print() {
System.out.println("Msg in Country Class");
}
}
-------------------------------------------------------
ublic class Capital implements Interface {
public String capital_Name;
public String getCapital_Name() {
return capital_Name;
}
public void setCapital_Name(String capital_Name) {
this.capital_Name = capital_Name;
}
@Override
public void print() {
System.out.println("Msg print in Capital Class");
}
}
-----------------------------
Application Context XML
<bean id="country" class="com.test.autowiring.Country" autowire="byName">
<property name="country_Name" value="India"></property>
</bean>
<bean id="captial" class="com.test.autowiring.Capital">
<property name="capital_Name" value="Delhi"></property>
</bean>
-----------------------------------------
Main Class :
public class TestAutowireClass {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("ApplicationContext.xml");
Country con = (Country) applicationContext.getBean("country");
System.out.println("The captial of :"+con.getCountry_Name()+" is :"+con.getCaptial().getCapital_Name());
con.print();
}
}
--------------------------------
Output is ::
The captial of :India is
elhi
Msg in Country Class
But he said I should read more on this. I am not sure that I was right or not