• 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
     */
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    具体作用就是生成 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
  • 相关阅读:
    一文了解MySQL中的多版本并发控制
    JAVA webservice配置xfire
    Android Java exception 介绍
    【编译原理】Chapter1概述
    NVIDIA 7th SkyHackathon(二)开发套件的安装与测试
    postgresql源码学习(34)—— 事务日志⑩ - 全页写机制
    阿尔兹海默病智能诊断
    基于java的在线物流管理系统【原创】
    ubuntu 修改nginx端口
    jeesite vue教程
  • 原文地址:https://blog.csdn.net/qq_19457117/article/details/126786029