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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值