报告 Spring Bean @Component、@Service 等的注入点上的自动装配问题。
@Autowired
在 Spring Bean 构造函数上的不正确用法示例:
public interface FooInterface {...}
@Component public class FooBean implements FooInterface {...}
@Component public class OtherBean implements FooInterface {...}
@Component
public class MyComponent {
@Autowired
FooInterface foo; // 无法自动装配。 有不止一种 'FooInterface' 类型的 Bean。
// Beans: fooBean(FooBean.java), otherBean(OtherBean.java)"
}
示例:
@Component
public class MyComponent {
@Autowired
public MyComponent(BarBean bean) {...} // 报告“只允许一个 @Autowired 构造函数”
@Autowired
public MyComponent(FooBean bean) {...} // 报告“只允许一个 @Autowired 构造函数”
}
@Component
public class MyFactory { // 报告“没有匹配的 @Autowired 构造函数”
public MyFactory(String str) {...}
public MyFactory(int count) {...}
}
示例:
public class FooBeanClass {
@Autowired // 报告 '必须在有效 Spring Bean 中定义自动装配成员:@Component、@Service 等'
ServiceBean bean;
}