spring boot 扩展配置属性元数据json“提示"对于地图不起作用 [英] spring boot expand configuration properties metadata json "hints" for Map not work

查看:55
本文介绍了spring boot 扩展配置属性元数据json“提示"对于地图不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的项目中扩展配置元数据,正如

有什么我可以改变的地方吗?

解决方案

我发现了问题.

在我的代码中,我在 FooProperties 上注释了 @Import 和 @Autowird.当我删除这些注释并使用spring-boot-configuration-processor"依赖项时,它起作用了.

所以,这种情况可以正常工作.

I want to expand configuration metadata in my project just as mentioned in the documentation.

Usually, I can use the spring-boot-configuration-processor dependency to generate my own metadata. But in this case, I'm using Map<String, Foo> properties in my properties, and I want the IDE to show code hints when using these propertie.

Let me show you the code.

FooProperties

@ConfigurationProperteis("server.worker")
public class FooProperties {
    private int workerCount;
    private int subWorkerCount;
    private int limit;
    @NestedConfigurationProperty
    private Map<String, BooProperties> group = new HashMap<>();
    //getter and setter
}

BooProperties

public class BooProperties{
    private int workerCount;
}

additional-spring-configuration-metadata.json

{
  "properties":[{
    "name": "server.worker.group",
    "type":"java.util.Map<java.lang.String,com.FooProperties>",
    "description": ".....",
    "sourceType":"com.FooProperties"
  }],
  "hints":[{
    "name":"server.worker.group.keys",
    "providers":[{
      "name":"any"
    }]
  }, {
    "name":"server.worker.group.values",
    "providers" : [{
      "name":"class-reference"
    }]
  }]
}

And this is an image of my IDE, not showing any hints:

Is there anything I can change to make this work?

解决方案

I found the problem.

In my code, I annotated @Import and @Autowird on FooProperties. When I remove those annotations and use the 'spring-boot-configuration-processor' dependency, It works.

So, that case can work fine.

这篇关于spring boot 扩展配置属性元数据json“提示"对于地图不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆