1 问题描述
在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
指定默认值:
这样就不会有警告了:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。