Spring Autowiring only works with Interface

前端 未结 6 904
慢半拍i
慢半拍i 2020-12-16 13:53

I am quite new to spring framework and came across the following issue.

I have an interface ClassA, which is implemented by classed ClassA1

6条回答
  •  失恋的感觉
    2020-12-16 14:11

    I have similar problem with Autowiring abstract service. You can use without any problem code like this:

    @Autowired
    @Qualifier("classA1")
    private ClassA1 classA1;
    
    @Autowired
    @Qualifier("classA2")
    private ClassA2 classA2;
    

    This will be working only if you declare your bean like this

    
    

    Or like this

    @Component("classA1")
    public class ClassA1 {
    ...
    }
    

提交回复
热议问题