在
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"
}
]
}
-
之后发现自定义的配置可以自动提示,并且可以进行跳转了
网友评论