08-02-2023, 02:43 PM
I have a bean `Item<T>` which is required to be autowired in a `@Configuration` class.
@Configuration
public class AppConfig {
@Bean
public Item<String> stringItem() {
return new StringItem();
}
@Bean
public Item<Integer> integerItem() {
return new IntegerItem();
}
}
But when I try to `@Autowire Item<String>`, I get following exception.
"No qualifying bean of type [Item] is defined: expected single matching bean but found 2: stringItem, integerItem"
How should I Autowire generic type `Item<T>` in Spring?
@Configuration
public class AppConfig {
@Bean
public Item<String> stringItem() {
return new StringItem();
}
@Bean
public Item<Integer> integerItem() {
return new IntegerItem();
}
}
But when I try to `@Autowire Item<String>`, I get following exception.
"No qualifying bean of type [Item] is defined: expected single matching bean but found 2: stringItem, integerItem"
How should I Autowire generic type `Item<T>` in Spring?