0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CDIの勉強(その1)

0
Last updated at Posted at 2020-05-02

CDIの勉強(その1)

CDIについての実践的なサンプルは、以下の記事が参考になります。
https://blogs.oracle.com/wlc/weblogic-server-12cjava-ee-68-cdi1

実際にやってみた

はじめてのCDI

実際に実行したときのウェブブラウザの状態がこれです。
pic006.png

わかったことは、

  • コンテナ(アプリケーションサーバー)が、HelloEnglish (今回の場合、hello)のインスタンスを生成してくれる。
  • コンテナがインスタンスを生成するので、interface を宣言する必要がある。

スコープの指定

実際に実行したときのウェブブラウザの状態がこれです。
pic007.png

デフォルトのスコープと呼ばれる@Dependent の場合、Servletのライフサイクルと同じになりました。

Beanクラスに、@RequestScoped にした場合の実行例は次のようになりました。
HttpRequest毎に、Beanが消滅するので、何度やっても呼び出し回数は、1 であることは納得いきました。
pic008.png

セッションスコープの場合、ブラウザ毎に状態を持っていることの確認もできました。
キャプチャは、同じになってしまうので省略。

おまけ

おまけにて、Bean のライフライクルについての説明があった。

次回の記事はこちら になります。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?