[英]Autowire list of Beans in Spring an get their names
I have some Spring Beans of a specific type but with different names: 我有一些特定类型的Spring Bean,但名称不同:
@Bean public Car audi() { .. }
@Bean public Car mercedes() { .. }
@Bean public Car honda() { .. }
Now I can autowire all of them with: 现在我可以用以下方式自动装配所有这些:
@Autowired List<Car> cars;
With this I get all Car-objects. 有了这个,我得到了所有的Car-objects。
Is it possible to get also the bean names somehow? 是否有可能以某种方式获得bean名称?
M. Deinums评论有正确的解决方案
@Autowired Map<String, Car> carsAndNames;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.