package com.test.sping.beans.cycle;
public class Car {
public Car() {
System.out.println("Car's Constructor...");
}
private String brand;
public void setBrand(String brand) {
System.out.println("setBrand...");
this.brand = brand;
}
public void init() {
System.out.println("init...");
}
public void destroy() {
System.out.println("destroy...");
}
@Override
public String toString() {
return "Car{" +
"brand='" + brand + '\'' +
'}';
}
}
Main.java(com.test.sping.beans.cycle.Main)
package com.test.sping.beans.cycle;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans-cycle.xml");
Car car = (Car) ctx.getBean("car");
System.out.println(car);
// 关闭 IOC 容器
ctx.close();
}
}