Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException:
2021/10/25 20:41:38
本文主要是介绍Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException:,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
spring cloudalibaba 整合nacos动态配置的时候项目启动报错:
package pers.miracle.miraclecloud.system.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @author lgn * @version 1.0 * @date 2021/10/25 10:51 */ @RestController @RequestMapping("/nacos/nacosHelper") @RefreshScope public class NacosController { @Value("${common.name}") private String name; @Value("${common.info}") private String info; @RequestMapping("/getNacosInfo") public String get() { return "娱乐圈重磅曝光:"+name+info; } }
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.nacosController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'name' in value "${name}"
检查一下配置文件:
bootstrap.yml:
application.yml:
打开nacos配置页面查看:
查看一下 Data ID: 配置格式 配置内容书写格式是否正确:
Data ID: 配置格式 是否跟 bootstrap.yml,application.yml:里面一致。
我的application.yml中的项目名是:miracle-system
命名空间是:gene
文件后缀是:yml
所以我的Data ID如下:
miracle-system-gene.yml
配置内容:
1.如果使用yaml格式的配置文件, 一定要注意Nocos中配置的书写格式, 注意空格, 如果不输入空格,
使用@Value(“common.name”)会找不到对应的配置参数, 启动服务的时候会报错
在尝试中意外发现可以使用@Value(“common:name”)来获取配置参数, 获取到的是name:zhans 这段字符串.
错误例子:
common: name:吴亦凡
正确例子:
common: name: 吴亦凡 info: 大碗宽面!
这篇关于Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException:的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-20测试人员都是画画大神,让我看看谁还不会用代码图?
- 2024-05-20年薪百万的程序员都在用的摸鱼方式……
- 2024-05-19永别了,微服务架构!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了