r/SpringBoot • • Feb 11 '26

Question Injecting Dependency by calling the method name with which bean is defined in the context using [@Bean]

For the context, I am following spring-start-here and doing all the exercise and concept taught in the book. And I was trying to inject the bean through constructor but calling the bean with the method with which its created.

code:- https://gist.github.com/cmhandan/b7accf6afcfb7caab4af251268f0b37a

What mistake am i doing in above code, or whats going on?

5 Upvotes

4 comments sorted by

View all comments

Show parent comment

2

u/pronuntiator Feb 11 '26

You're right, I forgot autowire by name exists.