Spring IOC – Bean life cycle instantiation

As mentioned in the Spring startup process article, the initialization of the container starts with the refresh method, which calls the finishBeanFactoryInitialization method during the initialization process. In this method, the DefaultListableBeanFactory#preInstantiateSingletons method will be called. The core function of this method is to initialize non-lazy-loaded beans, and provides two extension points. The source code […]

Hand-written spring instantiation bean source code, implementing the Object getBean(String beanId) method through the reflection mechanism

The handwritten spring instantiation bean source code only implements the Object getBean(String beanId) method. That is to achieve: ApplicationContext applicationContext = new ClassPathXmlApplicationContext(“xxx”); Object o = applicationContext.getBean(“xxx”); //Define ApplicationContext interface: public interface ApplicationContext {<!– –> Object getBean(String name); } // ClassPathXmlApplicationContext class /** * Parse xml files, read tags, and instantiate objects * @param springPath […]

Spring instantiation source code analysis circular dependency CircularReference (13)

Foreword First of all, what is circular dependency? Simply put, it means referencing each other. Spring supports circular dependencies by default. As for how to solve the circular dependency problem, this is what this chapter will discuss. // Allow circular dependencies by default private boolean allowCircularReferences = true; //Provide set method public void setAllowCircularReferences(boolean allowCircularReferences) […]

FactoryBean for Spring instantiation source code analysis (11)

Originally, this chapter needed to explain the instantiation process of singleton beans, but suddenly I discovered that the custom FactoryBean was actually instantiated during registerBeanPostProcessors, and I planned to find out. The function and usage of FactoryBean have been explained in the article Manually Implementing the Mybatis Proxy Interface Object. This chapter mainly analyzes the […]

Springboot extension point series_SmartInstantiationAwareBeanPostProcessor

Features The following figure shows the UML class diagram of the SmartInstantiationAwareBeanPostProcessor extension point. It can be seen that SmartInstantiationAwareBeanPostProcessor inherits the InstantiationAwareBeanPostProcessor interface, and the InstantiationAwareBeanPostProcessor interface inherits BeanPostProcessor. For the functional characteristics, implementation examples, and working principles of the InstantiationAwareBeanPostProcessor and BeanPostProcessor interfaces, see Springboot extension point Instanti ationAwareBeanPostProcessor and The Springboot extension […]

Spring instantiation source code analysis of Bean instantiation (12)

Foreword This chapter begins by analyzing the finishBeanFactoryInitialization(beanFactory) method, which literally means completing the initialization of the Bean factory, and in the middle is the instantiation process of the non-lazy singleton Bean. ConversionService has been analyzed in advance in Chapter 10. The key point is the last sentence, and our bean instantiation analysis starts from […]

Spring instantiation source code analysis of ConversionService (10)

Foreword ConversionService is a core interface in the Spring framework, used for conversion and formatting operations between different types. It provides a unified way to handle type conversions between objects, as well as converting data from one representation to another. Here are some of the main uses of ConversionService: Type conversion: ConversionService allows automatic conversion […]

Spring instantiation source code analysis of Custom Events (Part 8)

Introduction to using Events In the ApplicationContext, event handling is provided through the ApplicationEvent class and ApplicationListener interface. If a bean that implements the ApplicationListener interface is deployed into the context, the bean will be notified whenever an ApplicationEvent is posted to the ApplicationContext. Essentially, this is the standard observer design pattern. Official website address […]

Spring instantiation source code analysis of MessageSource (7)

Foreword After reading the source code of registerBeanPostProcessors, the next step is to enter initMessageSource. The main function of this step is to initialize the internationalization file. Source code analysis This source code is a Java method used to initialize the message source (MessageSource). In the Spring framework, message sources are used to provide localized […]