Spring-injecting-inner-beans
提供:Dev Guides
春-インナーBeanの注入
ご存じのとおり、Java内部クラスは他のクラスのスコープ内で定義されます。同様に、*インナーBean *は別のBeanのスコープ内で定義されるBeanです。 したがって、<property/>または<constructor-arg/>要素内の<bean/>要素はインナーBeanと呼ばれ、以下に示されています。
例
作業中のEclipse IDEを用意し、次の手順に従ってSpringアプリケーションを作成します。
Steps | Description |
---|---|
1 | Create a project with a name SpringExample and create a package com.finddevguides under the *src *folder in the created project. |
2 | Add required Spring libraries using Add External JARs option as explained in the Spring Hello World Example chapter. |
3 | Create Java classes TextEditor, SpellChecker and MainApp under the com.finddevguides package. |
4 | Create Beans configuration file Beans.xml under the* src* folder. |
5 | The final step is to create the content of all the Java files and Bean Configuration file and run the application as explained below. |
以下は TextEditor.java ファイルの内容です-
以下は、別の依存クラスファイル SpellChecker.java の内容です-
以下は MainApp.java ファイルの内容です-
以下は、設定ファイル Beans.xml です。このファイルには、セッターベースのインジェクションの設定がありますが、*内部Bean *が使用されています-
ソースおよびBean構成ファイルの作成が完了したら、アプリケーションを実行しましょう。 すべてがあなたのアプリケーションでうまくいけば、それは次のメッセージを印刷します-