如果同一個接口有多個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")