文章目录
前言
自己定义的starter,配置yml文件时没有提示,如何增加提供功能?
demo以ip-spring-boot-starter为例。
如何开启yml提示
- 进入到ip-spring-boot-starter工程,导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
点击complie之后,在target\classes\META-INF目录下,生成了一个spring-configuration-metadata.json文件,将这个文件复制到resources\META-INF目录下。此时可以移除上面的spring-boot-configuration-processor这个依赖了。
此时,再去yml文件检查发现有提示了
但是输入model 时,没有提示候选项。怎么添加候选项?
此时给model添加候选项,打开spring-configuration-metadata.json,找到hints,添加候选项
"hints": [
{
"name": "tools.ip.model",
"values": [
{
"value": "detail",
"description": "详细模式"
},
{
"value": "simple",
"description": "简单模式"
}
]
}
]
- 此时将ip-spring-boot-starter重新clean和install到仓库
- 进入到springboot-hello(引用到ip-spring-boot-starter的工程)工程,在yml文件设置配置,可以看到model也有候选提示了。
- yml提示功能大功告成。
遇到的问题
1. yml提示重复显示
解决方案:移除依赖的spring-boot-configuration-processor包,并且,重新执行complie
本文含有隐藏内容,请 开通VIP 后查看