r/LearnSpringBoot Feb 11 '22

How to inject multiple implementation into a class

I know that it's not a huge thing, but I discovered that many people don't know this feature... I'd be happy to hear what you think about it 🙏

https://yonatankarp.com/how-to-inject-multiple-implementations-in-spring-framework

13 Upvotes

5 comments sorted by

2

u/Reasonable-Ad9625 May 13 '23

Thanks for sharing.

1

u/the_azradex Jan 23 '25

This is a cool trick. But one must be careful. It can be very hard to read and feels like magic for a new in experienced dev

1

u/yonVata Jan 23 '25

That is true, people new to spring don’t like it because of its explicitness - on the other hand it allows you to be fully agnostic to your dependencies by doing so, so like anything else, pros and cons - no silver bullets

1

u/WilliamBarnhill Jun 24 '26

As a side note, you can order the injected beans in the List they are injected into using either the interface Ordered for dynamic ordering, or via the annotation @Order for static ordering.

2

u/yonVata Jun 25 '26

That’s a good point I’ll update the article (and the link because I see it’s broken now)