Skip to content

Exploring spring bean lifecycle: BeanDefinition, BeanFactoryPostProcessor, BeanPostProcessor, Init callbacks.

Notifications You must be signed in to change notification settings

maximkhvatovv/spring-bean-lifecycle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bean Lifecycle

Rough pseudocode:

Read configs(xml-based, annotation-based, java-based)

Construct BeanDefinitions

Sort BeanDefinitions

Pass BeanDefinitions through each BeanFactoryPostProcessor

for each BeanDefinition{
  - Invoke Bean Constructor
  for each Bean{
    - Invoke Setters
    - pass each bean through postProcessBeforeInitialization() of each BeanPostProcessor
    - Invoke Initialization Callbacks:
       1. @PostConstuct
       2. afterPropertiesSet() from InitializingBean
       3. init-method 
    - pass each bean through postProcessAfterInitialization() of each BeanPostProcessor (wrapping beans in proxy)
  }
}

Fully configured Singleton beans are stored in BeanFactory map `singletonObjects` (located in DefaultSingletonBeanRegistry)

On calling close() method in ConfigurableApplicationContext object:
  for each SingletonBean{
      - Invoke Destruction Callbacks:
        1. @PreDestroy
        2. destroy() from DisposableBean
        3. destroy-method 
  }

About

Exploring spring bean lifecycle: BeanDefinition, BeanFactoryPostProcessor, BeanPostProcessor, Init callbacks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages