How about this solution:
@Component public class WithAllMyInterfaceImpls { @Autowire List<MyInterface> allBeansThatImplementTheMyInterface; }
The list is filled only once (at startup), so it should not have a significant impact on the "normal" performance of execution.
A comment:
can you explain your code
You know that Spring is an IOC container. @Component tells Spring that it must instantiate this class (the so-called Spring Managed Bean)). IOC also means that the Container is responsible for injecting links to other instances (Spring Managed Beans). @Autowire (as well as @Resource and @Inject - all do the same) - this is such an annotation that tells Spring that this field should be populated by Spring. Spring itself tries to figure out with what instances the field should be populated. The default method used by Spring is by type , which means that Spring checks the type of the field and looks for suitable beans. In your case, this is a general list - this is a bit special. In this case, Spring populate the field with a list, where all beans elements are generic.
Ralph
source share