Spring初始化Ioc容器的三种方法
2012-05-24 11:07
344 查看
1、
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Student stu = (Student)context.getBean("student");
stu.setEmail("abc@126.com");
2、
String filePath = SpringAction.class.getResource("/").getPath();
filePath = filePath.substring(1);
Resource resource = new FileSystemResource(filePath+"applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(resource);
Student stu1 = (Student)factory.getBean("student");
stu1.setEmail("abc@163.com");
3、
ClassPathResource cr = new ClassPathResource("applicationContext.xml");
BeanFactory beans = new XmlBeanFactory(cr);
Student stu2 = (Student)beans.getBean("student");
stu2.setEmail("abc@qq.com");
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Student stu = (Student)context.getBean("student");
stu.setEmail("abc@126.com");
2、
String filePath = SpringAction.class.getResource("/").getPath();
filePath = filePath.substring(1);
Resource resource = new FileSystemResource(filePath+"applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(resource);
Student stu1 = (Student)factory.getBean("student");
stu1.setEmail("abc@163.com");
3、
ClassPathResource cr = new ClassPathResource("applicationContext.xml");
BeanFactory beans = new XmlBeanFactory(cr);
Student stu2 = (Student)beans.getBean("student");
stu2.setEmail("abc@qq.com");
相关文章推荐
- Spring容器实例Bean的三种方法(IOC三种方法)
- spring(IOC) 对象创建时机、对象作用域scope、对象的初始化方法和销毁方法的调用、spring容器总结
- spring容器的三种初始化方法
- Spring源码分析(二)-Spring IoC容器的初始化No.1
- Spring容器中的Bean几种初始化方法和销毁方法的先后顺序
- Spring的IOC、Spring对象初始化bean时机、Spring容器生命周期
- Spring 容器IOC的初始化过程
- 【Spring实战】Spring容器初始化完成后执行初始化数据方法
- spring中bean的作用域与懒加载及初始化方法和销毁方法以及spring容器的正常关闭
- Spring容器中的Bean几种初始化方法和销毁方法的先后顺序
- spring 在web容器启动时执行初始化方法
- 当spring 容器初始化完成后执行某个方法
- Spring技术内幕之IOC容器的实现(01)-IOC容器初始化过程
- 当spring 容器初始化完成后执行某个方法
- Spring源码阅读(二)—IOC容器初始化
- Spring源码解析二:IOC容器初始化过程详解
- Spring IOC源码详解之容器初始化
- spring IOC容器创建对象的三种方式
- spring中bean的作用域与懒加载及初始化方法和销毁方法以及spring容器的正常关闭
- spring 在web容器启动时执行初始化方法