Well, interviewer, before I start, I’ll talk about two common scopes:
- Spring container can be managed
singletonThe lifecycle of a scoped bean, in which spring knows exactly when the bean is created, initialized, and destroyed.
prototypeSpring is only responsible for creating a scope bean. When the container creates an instance of a bean, the bean instance will be handed over to the client code management, and the spring container will no longer track its life cycle. Every client request
prototypeThe spring container creates a new instance of the scope bean, regardless of whether those instances are configured as
prototypeThe lifecycle of the scoped bean.
in other words,
singletonSpring manages the lifetime of type bean, and
prototypeType bean is only created by spring. Once created, it is no longer managed by spring.
Now I’ll give you a picture to show bean’s life, manual dog head.
Finally, I think I have to give this picture to you so that you can pass the interview successfully!
Pay attention to the official account and reply:
Bean's life, get HD brain map + XMIND file, of course, there are more wonderful articles!