Demo 类代码:
springbean xml 配置代码:
测试类代码:
spring 获取bean 第一种方法
BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("springDemo01.xml"));
System.out.println(beanFactory);
Demo demo = (Demo) beanFactory.getBean("demo");
demo.test();
spring 获取bean 第二种方法:
BeanFactory beanFactory = new XmlBeanFactory(new FileSystemResource("src/springDemo01.xml"));
System.out.println(beanFactory);
Demo demo = (Demo) beanFactory.getBean("demo");
demo.test();
spring 获取bean 第三种方法:
ApplicationContext beanFactory = new ClassPathXmlApplicationContext("springDemo01.xml");
System.out.println(beanFactory);
Demo demo = (Demo) beanFactory.getBean("demo");
demo.test();
spring 包依赖图: