Science & Technology

#6 Dependency Injection using Spring Boot

by Telusko

Share:

📚 Main topics

  • Creating a Spring Boot projectNavin creates a simple Maven project with Java 21 and no web dependency, then opens it in IntelliJ IDEA. 0:30
  • Understanding the IoC containerSpring Boot starts a Spring container inside the JVM, where Spring can create and manage selected class objects. 2:05
  • Getting an object from SpringThe application context returned by SpringApplication.run provides a way to request a bean using getBean. 7:48
  • Registering a componentAdding the Component annotation to the Dev class tells Spring to create and manage its object. 10:54

✨ Key takeaways

  • Avoid manually creating managed objectsCreating an object with new leaves its lifecycle to your code; Spring can manage it instead. 5:41
  • The container does not include every class by defaultSpring creates objects for classes it is told to manage, rather than all classes in the project. 10:54
  • Dependency injection in this exampleThe application retrieves the Dev object from Spring’s container and calls its build method. 11:57

🧠 Lessons learned

  • A running container is not enoughThe first attempt to retrieve Dev fails because Spring has not been told to register that class as a bean. 10:24
  • Use Component for Spring-managed classesMarking Dev as a component makes it available in the container and resolves the missing-bean error. 11:25

🏁 Conclusion/next steps

  • Next exampleThe next video will add a Laptop dependency to Dev and explore how Spring can manage that additional layer. 12:29

Transcript excerpt

0:00 welcome back aliens my name is Navin Reddy and in this video let's try to implement dependency injection using spring boot now till this point we have talked about what is dependenc injection we have talked about what is spring Boot and then we have also created a simple project with the help of the spring initializer and we got the web project but we are not going to use this project basically we let's create a new project without the web and let's try to implement depense injection okay so what I'm going to do is first of all let's create the simple project for that I'm

0:30 going to go to start. spring.io and here let's create a new project so I will click on Maven and I'm going to select Java here the version is 3.2.5 group ID is the Isco project name is my app of course this can be anything but that's in my app uh the Java version I have is 21 so and the jar packaging I'm not going to add any dependency because when you say you want to go for web you have to add web dependency but if you don't add any dependency you will get a default Spring Boot options I will

🔒 The full, searchable transcript is available with Pro.

🔒 Unlock Premium Features

This is a premium feature. Upgrade to unlock unlimited Q&A, transcripts, mindmaps, and translations.

🔒 Unlock Premium Features

Access to Chat is a premium feature. Upgrade now to unlock unlimited studying tools.

🔒 Unlock Premium Features

Access to Mindmap is a premium feature. Upgrade now to unlock unlimited studying tools.

🔒 Unlock Premium Features

Access to Translation is a premium feature. Upgrade now to unlock unlimited studying tools.

Get unlimited summaries, Q&A, transcripts and more with Pro

Upgrade to Pro

Suggestions

🔒 Unlock Premium Features

Access to AI Suggestions is a premium feature. Upgrade now to unlock unlimited studying tools.