ZPY博客

SpringBoot工程配置nacos报错Error creating bean with name ‘nacosConfigProperties’:Could not resolve placeholder ‘spring.application.name’ in value “${spring.application.name}”

按照nacos官网的教程配置nacos时报错如下:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'nacosPropertySourceLocator': Unsatisfied dependency expressed through field 'nacosConfigProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nacosConfigProperties': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.application.name' in value "${spring.application.name}"

 

无论是百度还是谷歌都搜不出什么有用的信息,无奈啊,新出的东西就是资料少。。看错误信息明显是在生成nacosConfigProperties时找不到配置文件里的spring.application.name,但是这个在application.properties里是有的啊。。后来在一篇文章中提到可能是加载顺序的问题,也就是说生成nacosConfigProperties时application.properties还没有读取。解决方法是新建bootstrap.properties文件,把nacos相关配置放到bootstrap.properties里。因为bootstrap.properties的加载优先级高于application.properties。

至此,成功解决问题。