application.properties提示Cannot resolve configurati

1 问题描述

在IDEA的Spring Boot工程中的application.properties文件中,如果自定义属性会如下提示:

Cannot resolve configuration property 'xxxx'

在这里插入图片描述

2 解决方式一

这其实是一个警告,可以不用理会,正常运行,

@Value("${}")

可以正常获取到值,最暴力的方法就是关闭这个检查:
在这里插入图片描述
进入设置中的Editor-->Inspection-->Spring-->Spring Boot-->Spring Boot application properties,去掉右边勾选.

3 解决方式二(推荐)

在这里插入图片描述
这里提示Defind Configuration key a,然后按Alt+Shift+Enter后,就会创建一个addtional-spring-configuration-metadata.json的文件:
在这里插入图片描述
这里name是指定属性名字,type是类型,可以加上defaultValue指定默认值:
在这里插入图片描述
这样就不会有警告了:
在这里插入图片描述

猜你喜欢

转载自blog.51cto.com/14415843/2482881