spring框架归根结底也是一个容器最底层实现是ConcurrentHashMap
链接: ConcurrentHashMap.
IOC
一共有三种:
创建对象的过程
控制反转 / 反转of控制
Inversion of Control
IOC过程
默认单例,只创一个对象
<bean class="com.lanou.test.bean.Order" id="order" scope="prototype"></bean>
原型模式,那几次就创建几个对象
scope="prototype"
单例模式,有且仅会创建一个对象
scope="singleton"
懒加载,加载的时候才会创建对象,效率高
lazy-init
初始化方法,初始化时就执行这个方法
init-method=""
注解式IOC过程
Mian
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:a.xml");
//启动spring容器
Animal animal = (Animal) context.getBean("animal");
Sy