Marcel
Marcel

Reputation: 4402

Autowire list of Beans in Spring an get their names

I have some Spring Beans of a specific type but with different names:

@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.

Is it possible to get also the bean names somehow?

Upvotes: 6

Views: 2153

Answers (1)

Marcel
Marcel

Reputation: 4402

M. Deinums comment had the correct solution

@Autowired Map<String, Car> carsAndNames;

Upvotes: 4

Related Questions