I agree with Franky. Here is an article with recommendations for how to add dependency in Spring. www.logicbig.com/tutorials/spring-framework/spring-core/types-of-dependency-injection.html
To add, starting with Spring 4.3, if a class, which is configured as a Spring bean, has only one constructor, the Autowired annotation can be omitted and Spring will use that constructor and inject all necessary dependencies.
Thanks for explaining this rather simply, but I think the last part of the video counters the use of DI completely. If you use an abstraction in a class but you need need to provide a qualifier with it that matches the one of the implementation you want then it basically is equivalent as new-ing the implementation up in the class directly. Your class is now directly tied to the implementation through its qualifier which is precisely what we try to avoid with DI and IoC. The class shouldn't be responsible of this, it should be configured elsewhere.
This is counterintuitive. Why do you decorate a field with @Autowired and then assign a value to it in the constructor anyway? If it should be autowired then why do you wire it yourself? Also I wouldn't call wireing a field dependency-injection. It's rather dependency-hacking. How would you override this for testing when it's virtually a hardcoded dependency?
Hey Erik, what do i do if i have a Component that has a parameter in its constructor? For example a String. How can i account for this paramter in my RestController class when i AutoWire the Component?
I still don't understand why this is better. "Hey look, we're doing something that will save you one line of code...minus the 2 lines of annotations it adds, but every once in a while it'll save you two seconds.....just forget about the 5 days you've wasted trying to figure out how to structure your program when your normal Java object constructors that perform required initialization of objects fire off multiple times for some unknown reason." I really wish people would stop "saving me time". :D I like how easily I can spit out code to a web server using the controller, but this stuff along with normal java event handling not working and multithreading being done differently...I feel like I'm wasting my life with all the "time savings."
I still have no clue how is that useful? doesn't that still instantiate a object of textwriter?(maybe not by your hand but I'm sure it will be instantiate in the background.
Terrible explanation tbh. Showing a stackoverflow post instead of providing some basics? 5 minutes into the video and nothing related to dependency injection?
dude.... you were doing so well, but totally missed the climax. There's no difference in your story between DI and explicitly instantiating one class or the other. You're misleading the noobs...
This video was gold! I was beginning to think I would never understand autowiring. Thank you!
It's better to use constructor injection for testability. Your methodnames also need to start with a small letter
Oops! You are right! Thanks
I agree with Franky. Here is an article with recommendations for how to add dependency in Spring. www.logicbig.com/tutorials/spring-framework/spring-core/types-of-dependency-injection.html
To add, starting with Spring 4.3, if a class, which is configured as a Spring bean, has only one constructor, the Autowired annotation can be omitted and Spring will use that constructor and inject all necessary dependencies.
Awesome explanation of dependency Injection! Ultimately I got some source where explanation is clear without confusion! Thank you.
Thanks sir! I respected your explanation
Man... this is by far the easiest and cleanest explanation I found on TH-cam regarding dependency injection. Go Erik..!
Great video man! thanks for taking the time to show us.
Cheers from Guadalajara
Thanks
Best Video on Dependency Injection. TY
Very good explanations for Dependency Injection in Spring Boot. thanks
u r just awesome with the examples
Hey Erik, thanks for this post! Great example for the @Autowired and @Qualifier!
Great video ! Solved a lot of my struggles with dependency injection.
Thanks for explaining this rather simply, but I think the last part of the video counters the use of DI completely. If you use an abstraction in a class but you need need to provide a qualifier with it that matches the one of the implementation you want then it basically is equivalent as new-ing the implementation up in the class directly. Your class is now directly tied to the implementation through its qualifier which is precisely what we try to avoid with DI and IoC. The class shouldn't be responsible of this, it should be configured elsewhere.
Thank you I found this very useful!
Youre a great communicator.
Thanks 👍🏾
I appreciate that!
Still at the end of video with two implementation you need qualifier which induces tightly coupleness
Thanks, Erik, nice lesson! Keep them coming. :)
You are welcome!
This is counterintuitive. Why do you decorate a field with @Autowired and then assign a value to it in the constructor anyway? If it should be autowired then why do you wire it yourself? Also I wouldn't call wireing a field dependency-injection. It's rather dependency-hacking. How would you override this for testing when it's virtually a hardcoded dependency?
Thank you, cleared things for me.
Great to hear!
Really good!! Thx a lot.
Stay safe.
Hey Erik, what do i do if i have a Component that has a parameter in its constructor? For example a String. How can i account for this paramter in my RestController class when i AutoWire the Component?
This is very helpful! Thank you
Is there any video series about spring boot from the beginning? On TH-cam
thanks
Thank you for the video. Can you please create a video on how to pull data from sql and display on the UI?
Thank you for this! Makes so much more sense now!
Use lombok RequiredArgsConstructor and declare dependencies as private final
Thank a lot Erik, this just made setter injection easier
Hey Erik this is just amazing. Can you please do a video on the getBeans method?
I need to go back and update this video! Everyone seems to love it. Maybe I"ll make a 2019 version :)
great tutorial
Thanks!
Thanks! Well explained.
You're welcome!
good, helped me a lot.
Glad it helped!
good tutorial
Thanks
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.event.ApplicationStartingEvent
why i getting this error?
I still don't understand why this is better. "Hey look, we're doing something that will save you one line of code...minus the 2 lines of annotations it adds, but every once in a while it'll save you two seconds.....just forget about the 5 days you've wasted trying to figure out how to structure your program when your normal Java object constructors that perform required initialization of objects fire off multiple times for some unknown reason." I really wish people would stop "saving me time". :D I like how easily I can spit out code to a web server using the controller, but this stuff along with normal java event handling not working and multithreading being done differently...I feel like I'm wasting my life with all the "time savings."
Thank you
where are the next parts:? What do you mean by @Component?
I have three videos in the playlist! th-cam.com/video/27I1M5RLplE/w-d-xo.html
It was difficult for me wrapping my head around using the applicationContext.xml to configure the DI
I still have no clue how is that useful? doesn't that still instantiate a object of textwriter?(maybe not by your hand but I'm sure it will be instantiate in the background.
Awesome!
You know IntelliJ has auto save right? Also day mode eww
I did not know that!
the interface does not have to be a Component
thanks a lot! :)
You are welcome!
write methods with first letter Caps wtf?
That was my bad!
CHILL FOR FUCKS SAKE
Zoom
I don't believe you have explained what happens at the background properly.
Terrible explanation tbh. Showing a stackoverflow post instead of providing some basics? 5 minutes into the video and nothing related to dependency injection?
dude.... you were doing so well, but totally missed the climax. There's no difference in your story between DI and explicitly instantiating one class or the other. You're misleading the noobs...
Methods with capital letters... the level of degeneration our society is reaching is alarming.
Anyway, good tutorial!
Am I the only one who finds it irritating that he is starting his method names in capital letters?
Joshua Caponong yes! I did fix that in the next video of the series