I was going through the spring documentation, and came across the following statement-
You can then use getBean to retrieve instances of your beans. The ApplicationContext interface has a few other methods for retrieving beans, but ideally your application code should never use them. Indeed, your application code should have no calls to the getBean() method at all, and thus no dependency on Spring APIs at all. For example, Spring’s integration with web frameworks provides dependency injection for various web framework components such as controllers and JSF-managed beans, allowing you to declare a dependency on a specific bean through metadata (e.g. an autowiring annotation).
Ref-https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html
In my application, I receive some parameters to my client method, based on Which, I inject proper implementation of Interface.
The way I do it is, to search for the bean id after concatenating those parameters.
For example- if I receive type=C
, subType=D
, I get the bean with bean id=typeCsubTypeD
by calling getBean(beanId).
i.e, my dependencies are decided on Run time.
I have gone through Why is Spring's ApplicationContext.getBean considered bad?
But, this does not cover my use case (as also addressed by a comment in that question).