【发布时间】:2019-05-11 21:52:11
【问题描述】:
如果有两个相同类型但名称不同的 bean。如果我们在变量上添加 @Qualifier ,是否会根据名称自动装配 bean?我在文档中看到,“作为后备 Spring 使用 bean 名称作为默认限定符值”。
@Component
class A{
}
@Component
class B extends A{
}
class C{
@AutoWired
A a;
//Will a be of type class A, even without @Qualifier...?
}
【问题讨论】:
-
C类中的字段是B类型的,所以它不可能将 beanA放在那里,因为它不能分配给 @987654325 类型的变量@. -
对....没想到这一点..假设它是A型..
标签: spring spring-boot autowired