LoginSignup
2
1

More than 5 years have passed since last update.

Spring Beanのライフサイクル

Last updated at Posted at 2017-10-08

Springframeworkを学習中なので、学習内容をまとめていこうかと思います。
細かいところは省略しています。

Beanのライフサイクル

DIコンテナで管理されるBeanのライフサイクルは以下の通り

  1. 初期化フェーズ
  2. 利用フェーズ
  3. 終了フェーズ

上記3フェーズの前後で何が行われているかを把握し、活用できるようにする。

初期化フェーズ

初期化フェーズには3つの工程がある。

  1. Bean読み込み
  2. Construct & DI
  3. Post Construct

Bean読み込み

  • Java Configなど、Bean定義を収集
  • Bean Factory Post Processorによる定義情報の書き換え

Construct & Dependency Injection

  • Beanのインスタンス化
  • インジェクション
    1. コンストラクタ
    2. セッター
    3. フィールド

Post Construct

Post Constructは3つの処理に分かれる。
1. 前処理
2. 初期化処理
3. 後処理
前処理、後処理はBean Post Processorによって行われる。
Bean Post Processorは org.springframework.bean.factory.config.BeanPostProcessor
を実装したクラス。

終了フェーズ

終了フェーズではPreDestroyが呼び出される。

以上です。お疲れ様でしたー。

参考書籍

Spring徹底入門 Spring FrameworkによるJavaアプリケーション開発

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1