Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans,报错解决
记录自己今天遇到的一个小bug:在做头像上传功能时,出现如下错误,我有一个Properties类是和配置文件所绑定的,@ConfigurationProperties:告诉SpringBoot将本类中的所有属性和配置文件中相关的配置进行绑定;
prefix = "":配置文件中下面的所有属性进行一一映射,一般@Component只有这个组件是容器中的组件,才能用容器提供的@ConfigurationProperties功能;
解决方法 1)直接把@Component注解注释掉
疑问:我也不知道为啥会成功,按理来说都没放进容器中,怎么会注入成功的,可能是其他注解有把这个类放入容器的功效,我现在也不知道,我用的注入方式是@Autowired,加上@Component注解以后,就会显示有两个bean,所以我注释掉一个就成功了。哪位大佬知道原理了可以在评论区告我一下,我想知道原因,万分感谢!
2)第二种方法就是将@Autowired注解改为@Resource(name="你的Properties类名称首字母小写即可"),这样虽然有两个bean,但是指定了要导入哪个bean,IOC容器就会给你提供相应的bean。
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans,报错解决相关推荐
- Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans,....
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or us ...
- Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or us
项目原来一直好好地,原来不怎么启动的模块,来了新任务,去启动了一下,发现报错 Consider marking one of the beans as @Primary, updating the c ...
- SpringBoot中提示:Consider marking one of the beans as @Primary, updating the consumer to accept multipl
场景 SpringBoot项目在启动时提示: Consider marking one of the beans as @Primary, updating the consumer to accep ...
- 【报错解决】The dependencies of some of the beans in the application context form a cycle:
一.报错信息 *************************** APPLICATION FAILED TO START ***************************Descriptio ...
- mysql报错:Duplicate entry ‘xx‘ for key ‘PRIMARY‘ 解决可行方案。已解决
mysql报错:Duplicate entry 'xx' for key 'xxux1' 解决可行方案.已解决 web开发多次遇到Duplicate entry 'xx' for key 'PRIMA ...
- 【Java报错】多数据源mapper异常more than one `primary` bean found among candidates: [sqlSessionFactory] 问题分析解决
1. 报错分析 项目使用了多个数据源,但是没有使用持久层框架,后期加入了 mybatis-plus 插件,启动项目时报错,信息如下: 2021-08-19 09:16:20 ERROR [,,,] [ ...
- 报错 org.springframework.beans.factory.BeanCreationException
2019独角兽企业重金招聘Python工程师标准>>> 一.问题背景: spring mvc eclipse启动报错:org.springframework.beans.factor ...
- SpringBoot报错:Could not autowire. No beans of ‘DiscussantMapper‘ type found
SpringBoot报错:Could not autowire. No beans of 'DiscussantMapper' type found 一.资源 @Mapper和@Repository注 ...
- [解决方法] spring-data-mongo 配置报错org.springframework.beans.factory.BeanCreationException
[解决方法] spring-data-mongo 配置报错org.springframework.beans.factory.BeanCreationException 参考文章: (1)[解决方法] ...
最新文章
- 相识、相恋、相伴【与51CTO的故事】
- Spring 中策略模式的 2 个经典应用,可以用来怼面试官了
- 吴恩达深度学习 ——深层神经网络(选择题)
- Robot Framework(十四):使用RF进行接口测试(上)
- android 距离测量工具,尺子距离测量app
- 数据库事务(Transaction)详解
- MyBatis中的JdbcType映射介绍
- 如何给华硕笔记本在光驱位加装另一块linux系统固态硬盘?
- Python 网络爬虫从0到1 (2):网络爬虫的特性、问题与规范
- python 实现126邮箱登录
- 前端播放视频有声音没有画面
- Python爬取微信公众号文章、点赞数
- python在线电影网站-四
- python 英文语义分析_spinrewriter英文伪原创工具,Python对接API示例
- 红米note4x线刷miui9国际版开发版
- 动态内存管理——tlsf
- vnc viewer 绿色版,6款超好用的vnc viewer 绿色版
- Win10 微软输入法(微软拼音) 不显示 选字栏(无法选字) 解决方法
- Keil5进行STM32F103C8T6的软件仿真
- MBR DBR分区系统详述