2 Dependency Injection with Spring

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • Configuring and using Spring Container
  • Using different types of configuration metadata to configure Spring Container
  • Understanding dependency resolution
  • Learning the advantages and disadvantages of autowiring
  • Performing explicit bean lookups in Spring Container
  • Learning different bean instantiation methods
  • Understanding scoped beans and available scopes
  • Learning how lazy bean creation works
  • Understanding life-cycle callbacks
  • Using bean definition profiles to create conditional bean configurations

This chapter explains how you can apply dependency injection using the Spring Application Framework. You first look at different formats of configuration metadata necessary for the Spring Container to create and wire up objects in the system. The chapter includes examples for XML-, annotation-based, and Java-based configuration metadata formats. The chapter covers the two dependency injection methods in detail—setter injection and constructor injection—and explains how the dependency resolution process works in the container. You find out how you can override bean definitions, learn what autowiring means, and discover different modes of autowiring that are available in ...

Get Beginning Spring now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.