nacos做配置管理时,依赖注入失败,${pattern.dateformat}无法被解析
问题
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder ‘pattern.dateformat’ in value “${pattern.dateformat}”
我的bootstrap.yml文件中的内容:
它会到loaclhost:8848去找:{spring-application.name}-{spring.profiles.active}.{spring.cloud.nacos.config.file-extension}文件,上述示例中,也就是去找feign-dev.yaml文件。
bootstrap.yml文件没问题!那问题就出在了nacos的配置中心
错误
我原本以为nacos配置id=配置文件名(不包括后缀)
以为已经选了配置格式是yaml,ID是 feign-dev,肯定就能找到。配置如图:
错误!
解决方案
DataId要包括文件后缀 yaml,也就是feign-dev.yaml!!!
问题解决,运行成功!!!
注意:一定一定要保证
DataId == {spring.application.name}-{spring.profiles.active}.{spring.cloud.nacos.config.file-extension}。我还因为feign拼成了fegin,导致识别不到,所以务必多看几遍,确保这俩是一致的。
正常情况就public默认就行,不用配置namespace。
如有不对,感谢大家批评指正。