Springboot 项目注入 bean 找到多个,而只需要一个报错
今天跑一个 SpringBoot 项目,报错找到一个或多个 Bean
1.错误信息
//错误信息
Consider marking one of the beans as @Primary, updating.to identify the bean that should be consumed.multiplebeansor using @oualifierConSUmeraccept
因为我在 serviceimpl 中注入了类,然后再 controller 中使用了注解自动注入,所以系统不知道用哪个 bean 了
2.解决办法
在需要注入到 controller 的类中上方添加注解 @Primary 表示为让 Spring 优先寻找 bean 进行注入
3.运行项目
运行成功