Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bean容器中注册BeanDefinition后,使用bean时才会实例化 #60

Open
bluehr opened this issue Sep 15, 2023 · 1 comment
Open

Comments

@bluehr
Copy link

bluehr commented Sep 15, 2023

bean容器作为BeanDefinitionRegistry和SingletonBeanRegistry的实现类,具备两者的能力。向bean容器中注册BeanDefinition后,使用bean时才会实例化。

这句话个人感觉是不是不太准确呢

在Spring容器中,有两种主要的Bean作用域:

Singleton(单例)作用域:对于单例作用域的Bean,它们在容器启动时(或懒加载情况下,在首次使用时)被实例化,并在容器的整个生命周期中只存在一个实例。这意味着无论何时从容器中请求这个Bean,都会获得同一个实例。单例Bean在容器启动时被初始化。

Prototype(原型)作用域:对于原型作用域的Bean,它们在每次被请求时都会创建一个新的实例。这意味着每次从容器中请求这个Bean时都会得到一个不同的实例。原型Bean在容器启动时并不会被初始化,而是在每次请求时才会创建新实例。

@DerekYRC
Copy link
Owner

@bluehr 对的,这只是前期实现,后面的内容增加了Prototype类型bean的支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants