//xml放在类路径下的获取方式
// ApplicationContext context = new ClassPathXmlApplicationContext(SystemProperties.SPRING_CONFIG_XML_PATH);
//ApplicationContext context = new ClassPathXmlApplicationContext(); 这种方式无法加载配置文件
//配置文件放在工程的直接目录下 (和src同级)这种方式也可以写绝对路径
ApplicationContext context = new FileSystemXmlApplicationContext(SystemProperties.SPRING_CONFIG_XML_PATH);
ProductService productService = context.getBean(ProductService.class);
System.out.println(productService);
/*BeanFactory factory = new XmlBeanFactory(new FileSystemResource(SystemProperties.SPRING_CONFIG_XML_PATH));
ProductService productService = factory.getBean(ProductService.class);
System.out.println(productService);*/
// ApplicationContext context = new ClassPathXmlApplicationContext(SystemProperties.SPRING_CONFIG_XML_PATH);
//ApplicationContext context = new ClassPathXmlApplicationContext(); 这种方式无法加载配置文件
//配置文件放在工程的直接目录下 (和src同级)这种方式也可以写绝对路径
ApplicationContext context = new FileSystemXmlApplicationContext(SystemProperties.SPRING_CONFIG_XML_PATH);
ProductService productService = context.getBean(ProductService.class);
System.out.println(productService);
//利用FileSystemResource,可以将配置文件放在工程直接目录下
1).BeanFactroy采用的是延迟加载形式来注入Bean的,即只有在使用到某个Bean时(调用getBean()),才对该Bean进行加载实例化,这样,我们就不能发现一些存在的 spring的配置问题。而ApplicationContext则相反,它是在容器启动时,一次性创建了所有的Bean。这样,在容器启动时,我们就可以发现Spring中存在的配置错误
/*BeanFactory factory = new XmlBeanFactory(new FileSystemResource(SystemProperties.SPRING_CONFIG_XML_PATH));
ProductService productService = factory.getBean(ProductService.class);
System.out.println(productService);*/