When using lookup method injection, collections do not work as they do for other injection points (e.g. constructor, setter).
For example, the following fails in Spring Boot with the error A component required a bean of type util.function.Supplier' that could not be found.:
@Component
public class ExtensionCaller implements ApplicationRunner {
@Lookup
public List<Supplier<String>> suppliers() {
return List.of();
}
@Override
public void run(ApplicationArguments args) throws Exception {
suppliers();
}
}
I would've expected that calling the method would work, returning all beans of type Supplier<String>.
Comment From: snicoll
I would've expected that calling the method would work, returning all beans of type Supplier
.
Unfortunately, that's not the case. @Lookup is really about a getBean whereas Collection<X> is syntactic sugar for the injection point (or getBeans).