Spring Boot Dependency Injection - What Is It? Tutorial and Example

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ย. 2024

ความคิดเห็น • 69

  • @akshitaagarwal2827
    @akshitaagarwal2827 5 ปีที่แล้ว +2

    This video was gold! I was beginning to think I would never understand autowiring. Thank you!

  • @frankyvertriest8011
    @frankyvertriest8011 6 ปีที่แล้ว +36

    It's better to use constructor injection for testability. Your methodnames also need to start with a small letter

    • @ProgramWithErik
      @ProgramWithErik  6 ปีที่แล้ว

      Oops! You are right! Thanks

    • @johnmoe2806
      @johnmoe2806 5 ปีที่แล้ว +1

      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

    • @liudasstonys1293
      @liudasstonys1293 4 ปีที่แล้ว +1

      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.

  • @shefalshukur
    @shefalshukur 4 ปีที่แล้ว +7

    Awesome explanation of dependency Injection! Ultimately I got some source where explanation is clear without confusion! Thank you.

  • @DunTrann
    @DunTrann ปีที่แล้ว

    Thanks sir! I respected your explanation

  • @devolee8302
    @devolee8302 5 ปีที่แล้ว +1

    Man... this is by far the easiest and cleanest explanation I found on TH-cam regarding dependency injection. Go Erik..!

  • @Kalashnikova1991
    @Kalashnikova1991 5 ปีที่แล้ว +1

    Great video man! thanks for taking the time to show us.
    Cheers from Guadalajara

  • @xahmiyuto7844
    @xahmiyuto7844 3 ปีที่แล้ว

    Best Video on Dependency Injection. TY

  • @anar.xocayev
    @anar.xocayev 4 ปีที่แล้ว

    Very good explanations for Dependency Injection in Spring Boot. thanks

  • @bullsbearsfight
    @bullsbearsfight 2 ปีที่แล้ว

    u r just awesome with the examples

  • @moem9315
    @moem9315 5 ปีที่แล้ว +1

    Hey Erik, thanks for this post! Great example for the @Autowired and @Qualifier!

  • @murilo.g.t
    @murilo.g.t 3 ปีที่แล้ว

    Great video ! Solved a lot of my struggles with dependency injection.

  • @asmodeos666
    @asmodeos666 ปีที่แล้ว +3

    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.

  • @himym910
    @himym910 5 ปีที่แล้ว +1

    Thank you I found this very useful!

  • @MrMakemusicmike
    @MrMakemusicmike 11 หลายเดือนก่อน

    Youre a great communicator.
    Thanks 👍🏾

  • @jainamshah3691
    @jainamshah3691 6 หลายเดือนก่อน

    Still at the end of video with two implementation you need qualifier which induces tightly coupleness

  • @stefan4800
    @stefan4800 6 ปีที่แล้ว +2

    Thanks, Erik, nice lesson! Keep them coming. :)

  • @this-is-bioman
    @this-is-bioman 4 ปีที่แล้ว +2

    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?

  • @Murga_Mutton
    @Murga_Mutton 3 ปีที่แล้ว

    Thank you, cleared things for me.

  • @MCcrafterDE
    @MCcrafterDE 4 ปีที่แล้ว

    Really good!! Thx a lot.
    Stay safe.

  • @TheFailCrewTM
    @TheFailCrewTM 4 ปีที่แล้ว +2

    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?

  • @xsendilien9551
    @xsendilien9551 4 ปีที่แล้ว

    This is very helpful! Thank you

  • @hitendrasonkushare9095
    @hitendrasonkushare9095 5 ปีที่แล้ว +1

    Is there any video series about spring boot from the beginning? On TH-cam

  • @gohome2828
    @gohome2828 3 ปีที่แล้ว

    thanks

  • @AnNguyen-dq2mn
    @AnNguyen-dq2mn 6 ปีที่แล้ว

    Thank you for the video. Can you please create a video on how to pull data from sql and display on the UI?

  • @keyboardbandit
    @keyboardbandit 5 ปีที่แล้ว +1

    Thank you for this! Makes so much more sense now!

  • @paulfrischknecht3999
    @paulfrischknecht3999 3 ปีที่แล้ว

    Use lombok RequiredArgsConstructor and declare dependencies as private final

  • @ahmedsaka9648
    @ahmedsaka9648 5 ปีที่แล้ว

    Thank a lot Erik, this just made setter injection easier

  • @satwikburman6841
    @satwikburman6841 5 ปีที่แล้ว

    Hey Erik this is just amazing. Can you please do a video on the getBeans method?

    • @ProgramWithErik
      @ProgramWithErik  5 ปีที่แล้ว

      I need to go back and update this video! Everyone seems to love it. Maybe I"ll make a 2019 version :)

  • @TapuMandal
    @TapuMandal 4 ปีที่แล้ว

    great tutorial

  • @e2thee1
    @e2thee1 6 ปีที่แล้ว

    Thanks! Well explained.

  • @gengluan7439
    @gengluan7439 4 ปีที่แล้ว

    good, helped me a lot.

  • @arunabraham100
    @arunabraham100 4 ปีที่แล้ว

    good tutorial

  • @logaintheran1328
    @logaintheran1328 4 ปีที่แล้ว

    Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.event.ApplicationStartingEvent
    why i getting this error?

  • @michaelsanders9147
    @michaelsanders9147 ปีที่แล้ว

    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."

  • @batuhansahan
    @batuhansahan 6 ปีที่แล้ว

    Thank you

  • @KrishnaDasPC
    @KrishnaDasPC 5 ปีที่แล้ว +1

    where are the next parts:? What do you mean by @Component?

    • @ProgramWithErik
      @ProgramWithErik  5 ปีที่แล้ว +1

      I have three videos in the playlist! th-cam.com/video/27I1M5RLplE/w-d-xo.html

  • @ahmedsaka9648
    @ahmedsaka9648 5 ปีที่แล้ว

    It was difficult for me wrapping my head around using the applicationContext.xml to configure the DI

  • @临高
    @临高 4 ปีที่แล้ว

    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.

  • @testingtrail
    @testingtrail 5 ปีที่แล้ว

    Awesome!

  • @LeonTG
    @LeonTG 5 ปีที่แล้ว +1

    You know IntelliJ has auto save right? Also day mode eww

  • @paulfrischknecht3999
    @paulfrischknecht3999 3 ปีที่แล้ว

    the interface does not have to be a Component

  • @jhonnykokos8522
    @jhonnykokos8522 6 ปีที่แล้ว

    thanks a lot! :)

  • @petmik5022
    @petmik5022 6 ปีที่แล้ว +2

    write methods with first letter Caps wtf?

  • @anilraghu8687
    @anilraghu8687 3 หลายเดือนก่อน

    Zoom

  • @chenyangwang7232
    @chenyangwang7232 4 ปีที่แล้ว

    I don't believe you have explained what happens at the background properly.

  • @Bishonen88
    @Bishonen88 4 ปีที่แล้ว +2

    Terrible explanation tbh. Showing a stackoverflow post instead of providing some basics? 5 minutes into the video and nothing related to dependency injection?

  • @victorrosu5624
    @victorrosu5624 2 ปีที่แล้ว

    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...

  • @jorgegallego9672
    @jorgegallego9672 ปีที่แล้ว

    Methods with capital letters... the level of degeneration our society is reaching is alarming.
    Anyway, good tutorial!

  • @joshuacaponong3397
    @joshuacaponong3397 4 ปีที่แล้ว

    Am I the only one who finds it irritating that he is starting his method names in capital letters?

    • @ProgramWithErik
      @ProgramWithErik  4 ปีที่แล้ว +1

      Joshua Caponong yes! I did fix that in the next video of the series