Spring 的研究笔记
Spring 的研究笔记
Spring 框架的核心是 AOP、IOC、DI。其中,学习重点是 IOC 容器如何解决 Bean 的循环依赖问题。
BeanFactor 和 ApplicationContext 区别
BeanFactor 是懒加载的,而 ApplicationContext 默认是非懒加载。 ApplicationContext 是 BeanFactor 的一种扩展。
控制反转
IOC 容器可以用来管理资源,使得不同资源间依赖程度降低。
依赖倒置
资源使用第三方来管理,而不使用资源使用方或者提供方来管理。这样可以降低模块间的耦合度。
使用
配置 Bean 的作用域对象
不指定 @Scope 的情况下,所有的 Bean 都是单实例的 Bean, 而且是非懒加载
@Scope
@Scope 的取值及其作用域
| 值 | 作用域 |
|---|---|
| singleton | 单例模式(默认) |
| prototype | 多实例懒加载 |
| request | 同一次请求 |
| session | 同一次会话 |
向 IOC 中添加 Bean的方式
- Beans.xml
- @Bean
- @CompentScan + @Compent
- @Import
- @ImportBeanDefinitionRegister
