autowired

How to inject(autowired) beans to map with enum as map key in spring?

不打扰是莪最后的温柔 提交于 2020-07-18 07:47:20
问题 I've learned that in spring, i can autowire/inject into Map<String, SomeBeanInterface> by configured name like below: public interface DummyInterface{ } @Component("impl1") public class Impl1 implement DummyInterface{ } @Component("impl2") public class Impl2 implement DummyInterface{ } public class SomeUsage{ @Autowired private Map<String, DummyInterface> mapping; // ... } and retrieve the Component by string as key like: SomeUsage use = new SomeUsage(); DummyInterface dummy = use.getMapping(