对象可以包含下表中描述的属性:
每个 “hints” 元素的 providers 属性中的 JSON 对象可以包含下表中描述的属性:
3.4 配置元数据
所以如果想有更好的用户体验,可以为我们自定义的 starter 配置元数据,下面就为 HelloWorld 配置元数据。
在 META-INF 下创建 spring-configuration-metadata.json 文件:
在文件中输入如下内容:
{
"hints":[{
"name":"hello.msg",
"values":[{
"value":"你好",
"description":"中文方式打招呼"
},{
"value":"Hi",
"description":"英文方式打招呼"
}]
}],
"groups":[
{
"sourceType": "com.seagetech.spring.boot.helloworld.HelloWorldProperties",
"name": "hello",
"type": "com.seagetech.spring.boot.helloworld.HelloWorldProperties"
}],
"properties":[
{
"sourceType": "com.seagetech.spring.boot.helloworld.HelloWorldProperties",
"name": "hello.msg",
"type": "java.lang.String",
"description": "打招呼的内容",
"defaultValue": "Worlds"
}]
}
然后将 autoconfigure 模块重新打包,接下来就是在 spring-boot-demo 项目中使用,如下图所示,就有了属性的提示: