Files
rikako-note/spring/Spring core/SpringIOC.md
2023-10-22 22:55:22 +08:00

12 lines
832 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Spring IOC
## Bean Scope
### 简介
当创建一个bean定义时实际上根据bean定义创建了一个配方该配方用于创建类型的实际实例。可以基于一个配方创建多个对象实例。
### singleton
对于一个被容器管理的singleton bean来说只在容器中存在一个共享的实例。所有针对该bean的请求spring容器都会返回同一个实例。
当创建一个singleton bean定义时spring容器会为该bean定义创建一个实例该单实例会存储在cache中该cache专门用于存储类似的单实例对象。所有针对单实例对象的请求都会返回该cache中的对象。
singleton scope并不代表针对特定类型只创建一个实例对象。singleton scope代表在同一个容器中只会存在一个该类型的bean对象。