V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lslvxy
V2EX  ›  Java

求教一个 Java 问题,关于 configuration-processor 配置提示

  •  
  •   lslvxy · 2022-11-28 23:33:52 +08:00 · 1187 次点击
    这是一个创建于 486 天前的主题,其中的信息可能已经有所发展或是发生改变。
    com:
      github:
        xxx:
          - name: abc
            binder:
              type: aaa
              prop1: xxx
              prop2: yyy
              prop3: zzz
          - name: bcd
            binder:
              type: bbb
              prop4: ppp
              prop5: ooo
              prop6: iii
    

    自定义的配置如上的结构,每个 binder 都有固定的 type 字段,下面的字段则根据 type 的值配置的,不是固定写死的,我在 ConfigurationProperties 的类里面该怎么定义 POJO ,让 yaml 能识别到并自动提示呢

    5 条回复    2022-11-29 12:23:39 +08:00
    v2wtf
        1
    v2wtf  
       2022-11-29 00:05:03 +08:00
    ```
    class Binder {
    public String type;
    public String xxx;
    public String yyy;

    }

    class Item {
    public String name;
    public Binder binder;
    }

    class MyProperties {
    public List<Item> items;
    }
    ```
    lslvxy
        2
    lslvxy  
    OP
       2022-11-29 00:34:00 +08:00
    @v2wtf 不是这样的,属性名需要根据 type 的值自定义的
    chendy
        3
    chendy  
       2022-11-29 08:20:17 +08:00
    可以考虑这么一个结构,耦合性强了一些,但是处理起来比较方便:
    name: '', binder1: {}, binder2: {}, binder3: {}
    goalidea
        4
    goalidea  
       2022-11-29 10:05:42 +08:00
    写好 readme.md 比 ide 提示强
    zhady009
        5
    zhady009  
       2022-11-29 12:23:39 +08:00
    没生成 additional-spring-configuration-metadata.json 吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2423 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:10 · PVG 00:10 · LAX 09:10 · JFK 12:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.