application.properties提示Cannot resolve configuration property 'xxxx'

1 问题描述

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

Cannot resolve configuration property 'xxxx'

在这里插入图片描述

2 解决方式一

这实际上是一个警告,能够不用理会,正常运行,json

@Value("${}")

能够正常获取到值,最暴力的方法就是关闭这个检查:bash

在这里插入图片描述

进入设置中的Editor-->Inspection-->Spring-->Spring Boot-->Spring Boot application properties,去掉右边勾选.app

3 解决方式二(推荐)

在这里插入图片描述

这里提示Defind Configuration key a,而后按Alt+Shift+Enter后,就会建立一个addtional-spring-configuration-metadata.json的文件:code

在这里插入图片描述

这里name是指定属性名字,type是类型,能够加上defaultValue指定默认值:blog

在这里插入图片描述

这样就不会有警告了:图片

在这里插入图片描述

相关文章
相关标签/搜索