栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

IDEA 编写yml配置文件自动提示

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

IDEA 编写yml配置文件自动提示

实现自定义配置自动提示功能

我们发现在编写yml 或者Properties 配置文件的时候,写出前半部分会出现相关配置提示,如下:

1、创建一个Maven(我这里是SpringBoot)
  • 引入以下依赖

     org.springframework.boot 
    spring-boot-configuration-processor
     true 


// 这个我没有引入,使用spring boot自带的

    org.springframework.boot
    spring-boot-autoconfigure

2、编写配置信息
package com.nn.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;


@ConfigurationProperties(prefix = "zuul")
@Getter
@Setter
public class MyProperties {

    private String name;

    private String sex;

    private List ignorePath;
}
3、maven 编译打包
  • maven install 将项目发布到本地maven仓库中,以供其他项目依赖使用
  • 打包成功后在class目录下生成 “META-INF/spring-configuration-metadata.json” 文件
  • spring-configuration-metadata.json
{
  "groups": [
    {
      "name": "zuul",
      "type": "com.nn.config.MyProperties",
      "sourceType": "com.nn.config.MyProperties"
    }
  ],
  "properties": [
    {
      "name": "zuul.ignore-path",
      "type": "java.util.List",
      "sourceType": "com.nn.config.MyProperties"
    },
    {
      "name": "zuul.name",
      "type": "java.lang.String",
      "sourceType": "com.nn.config.MyProperties"
    },
    {
      "name": "zuul.sex",
      "type": "java.lang.String",
      "sourceType": "com.nn.config.MyProperties"
    }
  ],
  "hints": []
}
4、引入坐标

  • 在yml 配置中添加我们前面自定义的配置,就会出现自动提示

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/918981.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号