Spring 同一接口注入多个bean实现
如果同一个接口有多个bean实现类,spring在运行时会出现如下异常
required a single bean, but 2 were found:
marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
@Primary的意思是在众多相同的bean中,优先使用用@Primary注解的bean.而@Qualifier这个注解则指定某个bean有没有资格进行注入。
@Component
@Primary
@Autowired
@Component
@Qualifier("fjaoidfj")
@Autowired
@Qualifier("fjaoidfj")