How to Autowire Bean of generic type in Spring?

后端 未结 6 439
盖世英雄少女心
盖世英雄少女心 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:46

    Spring autowired strategy is defined in your configration file(application.xml).

    if you don't defined, default is by Type, spring inject use JDK reflect mechanism.

    so List?String? and List?Item?, the type is same List.class, so spring confused how to inject.

    and as above persons response, you should be point @Qualifier to tell spring which bean should be inject.

    i like spring configration file to define bean rather then Annotation.

    
     
            
                  <....>
            
     
    

提交回复
热议问题