Spring bean @Component, @Service 및 그 외의 삽입 지점에서 발생한 모든 오토와이어링 문제를 보고합니다.
@Autowired의 잘못된 사용 위치예:
public interface FooInterface {...}
@Component public class FooBean implements FooInterface {...}
@Component public class OtherBean implements FooInterface {...}
@Component
public class MyComponent {
@Autowired
FooInterface foo; // "오토와이어링을 수행할 수 없습니다. 'FooInterface' 타입의 bean이 2개 이상 있습니다.
// Bean: 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;
}