springboot基础(61):如何开启yml提示功能

发布于:2022-08-02 ⋅ 阅读:(280) ⋅ 点赞:(0)

前言

自己定义的starter,配置yml文件时没有提示,如何增加提供功能?

demo以ip-spring-boot-starter为例。

如何开启yml提示

  1. 进入到ip-spring-boot-starter工程,导入依赖
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
        </dependency>
  1. 点击complie之后,在target\classes\META-INF目录下,生成了一个spring-configuration-metadata.json文件,将这个文件复制到resources\META-INF目录下。此时可以移除上面的spring-boot-configuration-processor这个依赖了。
    在这里插入图片描述
    在这里插入图片描述

  2. 此时,再去yml文件检查发现有提示了
    在这里插入图片描述

  3. 但是输入model 时,没有提示候选项。怎么添加候选项?
    在这里插入图片描述

  4. 此时给model添加候选项,打开spring-configuration-metadata.json,找到hints,添加候选项

在这里插入图片描述

 "hints": [
    {
      "name": "tools.ip.model",
      "values": [
        {
          "value": "detail",
          "description": "详细模式"
        },
        {
          "value": "simple",
          "description": "简单模式"
        }
      ]
    }
  ]
  1. 此时将ip-spring-boot-starter重新clean和install到仓库
    在这里插入图片描述
  2. 进入到springboot-hello(引用到ip-spring-boot-starter的工程)工程,在yml文件设置配置,可以看到model也有候选提示了。
    在这里插入图片描述
  3. yml提示功能大功告成。

遇到的问题

1. yml提示重复显示

解决方案:移除依赖的spring-boot-configuration-processor包,并且,重新执行complie

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到