[JAVA] Spring bean life cycle

I'm learning the Spring framework, so I'd like to summarize what I've learned. The details are omitted.

Bean life cycle

The life cycle of beans managed by DI container is as follows

  1. Initialization phase
  2. Usage phase
  3. End phase

Understand what is happening before and after the above three phases so that you can utilize it.

Initialization phase

There are three steps in the initialization phase.

  1. Bean loading
  2. Construct & DI
  3. Post Construct

Bean loading

--Collect bean definitions such as Java Config --Rewriting definition information by Bean Factory Post Processor

Construct & Dependency Injection --Bean instantiation --Injection

  1. Constructor
  2. Setter
  3. Field

Post Construct Post Construct is divided into three processes.

  1. Pretreatment
  2. Initialization process
  3. Post-processing Pre-processing and post-processing are performed by Bean Post Processor. Bean Post Processor is ʻorg.springframework.bean.factory.config.BeanPostProcessor` A class that implements.

End phase

PreDestroy is called in the end phase.

that's all. good job.

Reference book

[Thorough introduction to Spring Java application development with Spring Framework](https://www.amazon.co.jp/Spring%E5%BE%B9%E5%BA%95%E5%85%A5%E9%96%80- Spring-Framework% E3% 81% AB% E3% 82% 88% E3% 82% 8BJava% E3% 82% A2% E3% 83% 97% E3% 83% AA% E3% 82% B1% E3% 83% BC% E3% 82% B7% E3% 83% A7% E3% 83% B3% E9% 96% 8B% E7% 99% BA-% E6% A0% AA% E5% BC% 8F% E4% BC% 9A % E7% A4% BENTT% E3% 83% 87% E3% 83% BC% E3% 82% BF / dp / 4798142476 /)

Recommended Posts

Spring bean life cycle
Bean scope and Bean Life Cycle
[Java] Spring DI ④ --Life cycle management
Activity life cycle
[Spring] Bean life cycle-from generation to destruction-
About the Android life cycle
Spring Bean Validaiton ~ Bean Bari Deshon ~
call spring management bean from pojo
Spring Framework bean definition XML: custom tag
DI SessionScope Bean in Spring Boot 2 Filter
File output bean as JSON in spring