美文网首页
SpringBoot自定义配置自动提示

SpringBoot自定义配置自动提示

作者: 皮多堡 | 来源:发表于2019-08-22 11:16 被阅读0次

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

添加注解处理器

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-configuration-processor</artifactId>
  <optional>true</optional>
</dependency>

修改IDEA配置

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

编译生成提示文件

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


{
  "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自定义配置自动提示

      本文链接:https://www.haomeiwen.com/subject/iutnsctx.html