package com.lc.ioc;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class App1 {
public static void main(String[] args) {
/*
* 1.从ApplicationContext中取bean
*/
//ApplicationContext ac=new ClassPathXmlApplicationContext("com/lc/ioc/beans.xml");
//当我们去实例化beans.xml,该文件中配置的bean被实例(该bean scope是 singleton)从bean中取出student
/*
* 2.通过文件路径来获取ApplicationContext(用的并不多)
*/
ApplicationContext ac=new FileSystemXmlApplicationContext("src\\com\\lc\\ioc\\beans.xml");
/*
* 3.从XmlBeanFactory获得
*/
//如果我们使用beanfactory去获取bean,当你只是实例化该容器, 那么容器的bean不被实例化,只有当你去使用getBean某个bean时,才会实时的创建.
// BeanFactory factory = new XmlBeanFactory(new ClassPathResource("com/lc/ioc/beans.xml"));
// factory.getBean("student");
/*
* 4.判断是不是单例的
*/
//获取两个student
Student s1=(Student) ac.getBean("student");
Student s2=(Student) ac.getBean("student");
System.out.println(s1+" "+s2);
}
}