Autowiring a collection via the constructor with Spring

后端 未结 4 1267
栀梦
栀梦 2021-02-07 01:31

I have what seems to be a simple problem, as stated in the title. Here is the kind of class I have :

public class Foo {
    @Autowired
    public Foo(@Qualifier(         


        
4条回答
  •  灰色年华
    2021-02-07 01:53

    I think this is because Spring interprets the autowiring of a collection as "give me all beans of type String", rather than "give me the bean which is a collection of String". The error message supports that idea.

    I don't think you can use autowiring for this. Short of manually wiring it up in the XML, the best I can suggest is:

    public class Foo {  
       private @Resource Set bar;
    }
    

提交回复
热议问题