r/SpringBoot • u/OakAndCobble • Apr 28 '26
Question Question about dependency injection
How do I manually inject dependencies into RequestController classes? I just started learning spring and from my bit of research, all I've come up with is the Autowired and Component/Service annotations.
I am still having a hard time understanding how exactly I tell spring what to build. If the dependency of my controller needs dependencies injected into it, what do I do? How do I specify which implementation of a dependency I want built? And so on.
Essentially, how do I get a bit more control of dependency creation and injection in a non-trivial situation, like the ones seen in examples on the internet?
Thanks in advance for any responses.
View all comments
Show parent comment
1
u/OakAndCobble Apr 29 '26
I want to specify which implementations of dependencies are injected into the controller by spring. Before I posted this question I kept hearing essentially "just use this and that annotation and spring will automatically inject the dependencies", but that makes absolutely no sense if your dependencies are interfaces with multiple implementations. So I was thinking there must be a way to specify what actually gets injected.