SpringBoot自定义配置自动提示

SpringBoot项目配置文件中如果使用自定义配置时IDE工具时不会自动提示的,如果想实现自动提示可按如下操作

编写自定义配置类

使用注解@ConfigurationProperties并指定前缀

@Component
@ConfigurationProperties(prefix = "zg.river")
@Data
public class RiverGlobalProperties {

    private String notAllowRefreshIndex;

    private String traceInterTime;

    private String patrolMaxTime;
}

编写对应的配置文件

zg:
  river:
    trace-inter-time: 5
    patrol-max-time: 10

添加注解处理器


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

修改IDEA配置

Settings --> Annotation Processor --> 勾选 Enable annotation processing

SpringBoot自定义配置自动提示_第1张图片

编译生成提示文件

  • 重新编译代码
  • 生成的文件如下classes/META-INF/spring-configuration-metadata.json


    SpringBoot自定义配置自动提示_第2张图片
{
  "hints": [],
  "groups": [
    {
      "sourceType": "com.zg.river.config.properties.RiverGlobalProperties",
      "name": "zg.river",
      "type": "com.zg.river.config.properties.RiverGlobalProperties"
    }
  ],
  "properties": [
    {
      "sourceType": "com.zg.river.config.properties.RiverGlobalProperties",
      "name": "zg.river.not-allow-refresh-index",
      "description": "notAllowRefreshIndex",
      "type": "java.lang.String"
    },
    {
      "sourceType": "com.zg.river.config.properties.RiverGlobalProperties",
      "name": "zg.river.patrol-max-time",
      "description": "patrolMaxTime",
      "type": "java.lang.String"
    },
    {
      "sourceType": "com.zg.river.config.properties.RiverGlobalProperties",
      "name": "zg.river.trace-inter-time",
      "description": "traceInterTime",
      "type": "java.lang.String"
    }
  ]
}
  • 之后发现自定义的配置可以自动提示,并且可以进行跳转了


    SpringBoot自定义配置自动提示_第3张图片

参考资料:

  • Configuration Metadata

你可能感兴趣的:(SpringBoot自定义配置自动提示)