Science & Technology

#11 Autowire in Spring

by Telusko

Share:

📚 Main topics

  • Using an interface for dependenciesThe tutorial adds a Computer interface implemented by Laptop and Desktop, then updates Developer to depend on Computer rather than a specific class. 0:32
  • Wiring beans in XMLA computer implementation can be injected into Developer by referring to its bean ID in the XML configuration. 3:36
  • Autowiring by nameSetting autowire to by name makes Spring match the Developer property name to a bean ID in the container. 7:13
  • Autowiring by type and primaryAutowiring by type finds beans matching the Computer type, but multiple matches cause ambiguity; marking one bean as primary tells Spring which to choose. 9:16
  • Looking up a bean by typeThe application can retrieve a bean by its class rather than its ID. 10:51

✨ Key takeaways

  • Depend on abstractionsDeveloper can work with either Laptop or Desktop through the shared Computer interface. 2:05
  • Autowiring requires configurationSpring does not inject the dependency automatically unless autowiring is enabled. 7:13
  • Bean IDs must be uniqueAutowiring by name depends on a matching bean ID, and duplicate IDs cannot be used. 8:46

🧠 Lessons learned

  • Resolve type ambiguityIf multiple beans have the requested type, Spring needs a clear choice, such as a bean marked primary. 9:48
  • Choose name or type lookupSpring supports retrieving a bean by its ID or by its type, depending on the use case. 10:51

🏁 Conclusion/next steps

  • Move on to Spring BootThe video wraps up XML-based autowiring and says the series will focus more on Spring Boot and then a project. 11:23

Transcript excerpt

0:00 welcome back aliens my name is Navin Reddy and let's continue this series on Spring framework now to this point we were able to achieve Constructor and seter injection it's time to talk about Auto wiring if you remember when we talked about spring boot we have done this in Spring boot we have done with auto wiring but here also without spring boot let's try to explore it and even before we do that if you remember the spring boot videos we have talked about different classes and interfaces because in this case we only have laptop and Dev

0:32 developer uh what we don't have is computer interface and desktop implementation of it so let's create those and let's get forward so what I will do is I will just go back here and say let me just copy and paste or maybe use the same a laptop class but this time we'll name it as desktop and in desktop we'll change certain things I will just close this part and in desktop what I will do is when I say uh the structor should be desktop created and in the compiling I

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