视频地址:https://www.youtube.com/watch?v=RA9ag2v4Gq8 代码地址:https://github.com/gaohanghang/Spring/blob/master/springcore
容器管理对象的生命周期
代码地址:https://github.com/gaohanghang/Spring/blob/master/springcore
public class Main1 {
public static void main(String[] args) {
EmailService emailService = new EmailService();
emailService.sendEmail("[email protected]", "Hello from Miss Xing");
}
}
public class Main2 {
public static void main(String[] args) {
//BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("spring.xml"));
BeanFactory beanFactory = new ClassPathXmlApplicationContext("spring.xml");
EmailService emailService = beanFactory.getBean("emailService", EmailService.class);
emailService.sendEmail("[email protected]", "Hello from Miss Xing");
}
}
public class Main3 {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
EmailService emailService = context.getBean("emailService", EmailService.class);
emailService.sendEmail("[email protected]", "Hello from Miss Xing");
}
}