/*
Pro Spring
By Rob Harrop
Jan Machacek
ISBN: 1-59059-461-4
Publisher: Apress
*/
///////////////////////////////////////////////////////////////////////////////////////
//File: beans.xml
John Smith
35
1.78
true
1103760000
///////////////////////////////////////////////////////////////////////////////////////
public interface Oracle {
public String defineMeaningOfLife();
}
///////////////////////////////////////////////////////////////////////////////////////
public class InjectRef {
private Oracle oracle;
public void setOracle(Oracle oracle) {
this.oracle = oracle;
System.out.println(oracle.defineMeaningOfLife());
}
}
///////////////////////////////////////////////////////////////////////////////////////
public class BookwormOracle implements Oracle {
private Encyclopedia enc;
public void setEncyclopedia(Encyclopedia enc) {
this.enc = enc;
}
public String defineMeaningOfLife() {
return "Encyclopedia's are a waste of money - use the Internet";
}
}
///////////////////////////////////////////////////////////////////////////////////////
public class Encyclopedia {
}
///////////////////////////////////////////////////////////////////////////////////////
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
public class InjectSimple {
private String name;
private int age;
private float height;
private boolean isProgrammer;
private Long ageInSeconds;
public static void main(String[] args) {
BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
"build/beans.xml"));
InjectSimple simple = (InjectSimple)factory.getBean("injectSimple");
factory.getBean("injectRef");
System.out.println(simple);
}
public void setAgeInSeconds(Long ageInSeconds) {
this.ageInSeconds = ageInSeconds;
}
public void setIsProgrammer(boolean isProgrammer) {
this.isProgrammer = isProgrammer;
}
public void setAge(int age) {
this.age = age;
}
public void setHeight(float height) {
this.height = height;
}
public void setName(String name) {
this.name = name;
}
public String toString() {
return "Name :" + name + "\n"
+ "Age:" + age + "\n"
+ "Age in Seconds: " + ageInSeconds + "\n"
+ "Height: " + height + "\n"
+ "Is Programmer?: " + isProgrammer;
}
}
SimpleInjectByID.zip( 1,199 k)