How to Autowire Bean of generic type in Spring?

后端 未结 6 435
盖世英雄少女心
盖世英雄少女心 2020-11-28 03:51

I have a bean Item which is required to be autowired in a @Configuration class.

@Configuration
public class AppConfig {

          


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 04:42

    If you dont want to upgrade to Spring 4 you have to autowire by name as below :

    @Autowired
    @Qualifier("stringItem")
    private Item strItem; // Injects the stringItem bean
    
    @Autowired
    @Qualifier("integerItem")
    private Item intItem; // Injects the integerItem bean
    

提交回复
热议问题