Spring Boot扩展配置属性映射的元数据json“提示”不起作用

时间:2019-03-14 07:35:43

标签: java spring spring-boot

我想像the documentation中所述在项目中扩展配置元数据。

通常,我可以使用spring-boot-configuration-processor依赖项来生成自己的元数据。但是在这种情况下,我在属性中使用了Map<String, Foo>属性,并且希望IDE在使用这些属性时显示代码提示。

让我告诉你代码。

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"
    }]
  }]
}

这是我的IDE的图像,没有显示任何提示:

Image of IDE

要进行这项工作,我需要更改什么吗?

1 个答案:

答案 0 :(得分:0)

我发现了问题。

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

所以,这种情况可以很好地工作。