Autowiring a collection via the constructor with Spring

后端 未结 4 1266
栀梦
栀梦 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:55

    I had this same problem and was inspired by @rembisz's answer. That answer didn't work on my version of Spring (4.1.3). When I checked the SpEL documentation on bean references, I found a different SpEL syntax to express bean references in autowired values that worked for me - @beanname. As such, the following code worked for me:

    public class Foo {
        @Autowired
        public Foo(@Value("#{@bar}") Set bar) {
            // ...
        }
    }
    

提交回复
热议问题