01-Spring_ioc

一.Spring的容器对象

1.BeanFactory是spring容器的定层接口
2.接口ApplicationContext是BeanFactory的子接口; 
  实现类有:
  ClassPathXmlApplicationContext-->从类路径下读取配置文件 
  FileSystemXmlApplicationContext-->从绝对路径指定配置文件读取 
  AnnotationConfigApplication-->纯注解配置实用的类     

代码示例:

    ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml"); 
    Object userDao = ac.getBean("userDao");
3.BeanFactory与ApplicationContext的区别:
  BeanFactory创建容器对象时,只是加载了配置文件,没有创建对象,获取对象时,才创建对象。  
  ApplicationContext:在创建容器对象时,只创建单例模式的对象,多例模式的对象在获取时才创建对象

二.ClassLoader的api加载配置文件为输入流

//从类路径下读取配置文件 
InputStream in= Class.forName("").getClassLoader().getResourceAsStream("");

//从绝对路径指定配置文件读取
InputStream in= Class.forName("").getClassLoader().getSystemResourceAsStream("");  

三.SpringIOC容器默认创建的bean对象是单例的

四.实例化bean的三种方式

五.IOC (控制反转)

六.Spring 常用注解

七.Spring与junit的整合

八.Spring的核心包

org.springframeworkspring-context5.0.2.RELEASE

Last updated