A simple testing class showing my problem:
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringTest.OptionalConfiguration.class)
public class SpringTest {
static class Item extends Object {}
@Configuration
static class OptionalConfiguration {
@Bean
List<Item> someString() {
return new ArrayList<>();
}
@Bean
Object foo(List<Item> obj) {
return new Object();
}
}
@Test
public void testThis() {
}
}
Result:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualification bean of type [SpringTest $ Item] found for dependency [SpringTest $ Item collection]: at least 1 bean is expected to qualify as an autwire candidate for this dependency. annotation dependency: {}
If I change from List<Item>to Item, everything works.
Is it for design? Any workarounds? I need to provide Listelements - sometimes empty, sometimes with elements, depending on the configuration of the runtime.
, bean (s) Item, autowiring List<Item>. , bean List<Item> ( , List).
Spring 4.2.4.