parent
27310c5ea6
commit
0690729d42
@ -0,0 +1,7 @@
|
|||||||
|
package springIOC;
|
||||||
|
|
||||||
|
public class Driver {
|
||||||
|
public Driver(){
|
||||||
|
System.out.println("driver");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package springIOC;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ApplicationContext context = new ClassPathXmlApplicationContext("app.xml");
|
||||||
|
// Driver d = (Driver) context.getBean("d");
|
||||||
|
Tank t = (Tank) context.getBean("t");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package springIOC;
|
||||||
|
|
||||||
|
public class Tank {
|
||||||
|
private Driver driver;
|
||||||
|
|
||||||
|
public Driver getDriver() {
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDriver(Driver driver) {
|
||||||
|
this.driver = driver;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
|
<bean id="d" class="springIOC.Driver"></bean>
|
||||||
|
<bean id="t" class="springIOC.Tank">
|
||||||
|
<property name="driver" ref="d"></property>
|
||||||
|
</bean>
|
||||||
|
</beans>
|
Loading…
Reference in new issue