Spring-required-annotation
提供:Dev Guides
Spring @Required Annotation
例
動作する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 Student 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. |
これが Student.java ファイルの内容です-
以下は MainApp.java ファイルの内容です-
以下は、構成ファイル Beans.xml の内容です-
ソースおよびBean構成ファイルの作成が完了したら、アプリケーションを実行しましょう。 すべてがアプリケーションで問題ない場合、_BeanInitializationException_例外が発生し、他のログメッセージとともに次のエラーが出力されます-
次に、次のように「年齢」プロパティからコメントを削除した後、上記の例を試すことができます-
上記の例では、次の結果が生成されます-