Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to initialize Spring Bean

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report