アノテーションインターフェース NestedConfigurationProperty


@TargetSE({FIELDSE,RECORD_COMPONENTSE,METHODSE}) @RetentionSE(RUNTIMESE) @DocumentedSE @Nested public @interface NestedConfigurationProperty
@ConfigurationProperties オブジェクト内のプロパティをネストされた型として扱う必要があることを示します。このアノテーションは実際のバインディングプロセスには影響しませんが、プロパティが単一の値としてバインドされていないことを示すヒントとして spring-boot-configuration-processor によって使用されます。これを指定すると、プロパティのネストされたグループが作成され、その型が収集されます。

以下の例では、Host はフィールドを使用してネストされたプロパティとしてフラグが付けられ、Host が定義するプロパティを使用して example.server.host ネストされたグループが作成されます。


 @ConfigurationProperties("example.server")
 class ServerProperties {

     @NestedConfigurationProperty
     private final Host host = new Host();

     public Host getHost() { ... }

     // Other properties, getter, setter.

 }

getter メソッドでもアノテーションを指定できます。レコードを使用する場合は、レコードコンポーネントにアノテーションを付けることができます。

コレクションとマップには影響しません。これらの型は自動的に識別されるからです。また、ターゲット型が @ConfigurationProperties オブジェクトの内部クラスである場合、アノテーションは必要ありません。次の例では、Host は内部クラスとして定義されているため、ネストされた型として検出されます。


 @ConfigurationProperties("example.server")
 class ServerProperties {

     private final Host host = new Host();

     public Host getHost() { ... }

     // Other properties, getter, setter.

     public static class Host {

         // properties, getter, setter.

     }

 }
導入:
1.2.0
作成者:
Stephane Nicoll, Phillip Webb, Jared Bates