How to initialize Spring Bean
This article mainly shows you "how to initialize Spring Bean", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to initialize Spring Bean" this article.
Preface
I have been doing Java for many years, and I have always wondered how Spring initializes bean and how to call reflection instantiated objects. I used to think that the instantiation of spring bean objects has always been done by the BeanPostProcessor interface implementation class, but I just don't know which implementation class.
Three-level cache
Why the interviewer especially likes to ask to create a three-tier cache of bean, mainly because the creation of bean is accompanied by the transition between the three-level cache, and different states of objects are stored in different caches. I will support how objects flow in the cache when analyzing the code below. First, take a look at the spring three-level cache.
/ * * first-level cache is used to store singleton bean, that is, initialization is completed and all dependencies are injected * / private final Map singletonObjects = new ConcurrentHashMap (256); / * second-level cache exposes singleton objects prematurely, when bean has just completed initialization, attribute injection and execution of init method * / private final Map earlySingletonObjects = new ConcurrentHashMap (16) / * * three-level cache loads the factory object that created the bean * / private final Map