Dependency Injection Spring: How to use Dependency Injection in Spring Boot

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • In this tutorial, you will learn what Dependency Injection in Spring is by building a Spring Boot application. I love writing tests because they can expose some issues with how your application is constructed. Follow along as we write some Spring Boot tests that show the problems in our application and how Dependency Injection can solve them. By the end of this video, you will have a good idea of how to use Dependency Injection in your Spring applications.
    🔗Resources & Links mentioned in this video:
    Spring Dependency Injection Guide: tanzu.vmware.c...
    👋🏻Connect with me:
    Website: www.danvega.dev
    Twitter: / therealdanvega
    Github: github.com/dan...
    LinkedIn: / danvega
    Newsletter: www.danvega/de...
    SUBSCRIBE TO MY CHANNEL: bit.ly/2re4GH0 ❤️

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

  • @LeoLawrence-b7u
    @LeoLawrence-b7u 5 หลายเดือนก่อน

    As a SpringBoot beginner I found your explanation about DI extremely insightful. Kudos to you !

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

    I'm a beginning Java programmer, thrown into the deep end of the pool. I had to learn Java, Junit, Mockito, SpringFramework, Maven and a huge application in roughly 2 months. This video was a huge help... Thank you for taking the time to put this together. It will be a constant reference for me.

    • @bleachonacob4060
      @bleachonacob4060 2 หลายเดือนก่อน

      how are you doing so far?

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

    Absolutely wonderful demo and explanation for DI using SpringBoot.
    Inversion of Control --> Inverting the Control, i.e., Swapping the Responsibility of Creating/Managing the Object's(Preferably, Usually, a Singleton) lifecycle...
    Initially, this was done by the Developer (with new() keyword which is ugly and bad practice) but now letting the Spring Container do it for us. Before the DI & IoC, we had to do the hard work. But now the framework does all the hard work. The control is inverted :-D
    Spring framework scans for the annotations like @Component, @Service, @Repository, @RestController, and so on.
    Bonus: This video also shows how to use Mockito to write lightweight Unit Tests instead of heavyweight & time-consuming integration tests.

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

    I love how are you using unit tests to test stuff, very useful .

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

    This is amazing! Really helped solidify Dependency Injection for me. Thanks Dan you are a Spring legend :)

  • @benjamine.ndugga729
    @benjamine.ndugga729 ปีที่แล้ว +1

    Thanks Dan Vega.. love it , we do need more videos on Testing...

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

      I completely agree. I believe I saw you in Spring Office Hours yesterday, hope that discussion helped.

  • @programtin
    @programtin 2 หลายเดือนก่อน

    Absolutely wonderful

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

    I actually came into this video to see what is the best practice of DI in Spring, but I learned more than I expected :) Is it safely to say "Constructor Injection is the best practice" Dan?

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

    Thanks for the video. I'm using Spring Boot at work, but for controller tests I prefer applying a MockMvc object and mock service dependency in order to test for various controller HTTP code HttpHTTP EntityResponse codes like 200-400. In my personal point of view, this test approach more accurate and correct that instantiating and invoking the controller's method, because the controller is supposed to return entities "wrapped" in HTTP response codes and we can test the JSON output in case of REST APIs.

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

      Thanks for sharing!

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

    Thank you Dan very nice explanation

  • @KapilSharma-rp5le
    @KapilSharma-rp5le ปีที่แล้ว

    Amazing basics covered

  • @sugoi5240
    @sugoi5240 5 หลายเดือนก่อน +1

    hey do you mind slowing down a bit and take more time explaining the litte things >:D

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

    Thank you

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

    At 21:00 why are u not calling the slugify method as like this this.service.slugify
    Instead u calling without "this." Prefix ?
    Why this works this way?

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

      I really didn't need to use this on line 17. this refers to the current object and it's useful when you are trying to be specific when you have arguments of the same name being passed to the constructor. If you omit this Java just expects you mean the current object.

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

    Hey Dan, thanks a lot for this type of content! It's really enjoyable. Are you planning to make a video about custom error handling in Spring? I'm a begginer in the Spring world and would like to learn about how to manage properly the error responses for a REST api

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

      I am now, thanks for the suggestion github.com/danvega/office-hours/discussions/31

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

    Thanks Dan Vega for great session

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

      You're welcome, Shiva.

  • @OmerFarukAY-ij2xg
    @OmerFarukAY-ij2xg 3 หลายเดือนก่อน

    thank you! waiting excitedly for the new spring project videos

  • @OmerFarukAY-ij2xg
    @OmerFarukAY-ij2xg 3 หลายเดือนก่อน

    thank you ! it is so awesome that we have created rest api in 8 mins. powerful spring !

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

    Thank you for your time making the video about dependency injection that has been immensely helpful to me. Their clear and concise explanation of this complex topic has enabled me to better understand and implement this important software design pattern. Thank you so much for taking the time to share your knowledge and expertise with others.

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

    Hey Dan, thank you for all of your effort. I stuggle many time to understand the concept of dependency injection, but I learnt a lot by your channel

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

      I'm so glad I could be of help Alik.

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

    Excellent work Dan!
    Really easy to follow your explanations and benefits of Dependency Injection :)

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

      Glad you think so! Appreciate the kind words.