NestedConfigurationProperty的作用

spring-boot-configuration-processor 这个可以用来生成spring-configuration-metadata.json供IDE使用
https://www.jianshu.com/p/ca22783b0a35

NestedConfigurationProperty, 官方注释

/**
 * Indicates that a field in a {@link ConfigurationProperties @ConfigurationProperties}
 * object should be treated as if it were a nested type. This annotation has no bearing on
 * the actual binding processes, but it is used by the
 * {@code spring-boot-configuration-processor} as a hint that a field is not bound as a
 * single value. When this is specified, a nested group is created for the field and its
 * type is harvested.
 * <p>
 * This has no effect on collections and maps as these types are automatically identified.
 *
 * @author Stephane Nicoll
 * @author Phillip Webb
 * @since 1.2.0
 */

具体作用就是生成 spring-configuration-metadata.json 这个文件的时候,会把对应的嵌套类也生成一组对应的配置, 例如

class Inner {
	String a;
	String b;
	...get set...
}

@ConfigurationProperties(prefix="test")
class Properties {
	Inner inner;
	...get set...
}
// 1. 当Inner类不是Properties的内部类时
// 		不标注@Nest... 时 生成的 spring-configuration-metadata.json 文件里只有一个 test.inner
// 		标注@Nest... 时 生成的 spring-configuration-metadata.json 文件里只有一个 test.inner.a, test.inner.b
// 2. 当Inner是Properties的内部类时, 可以不用标注@Nest... 也会生成test.inner.a, test.inner.b

版权声明:本文为qq_19457117原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。