Topic 4
■■■
Introducing IoC and DI in Spring
In Chapter 1, we covered the basic principles of Inversion of Control (IoC) and Dependency Injection
(DI). Practically, DI is a specialized form of IoC, although you will often find that the two terms are used
interchangeably. In this chapter, we take a much more detailed look at IoC and DI, formalizing the
relationship between the two concepts and looking in great detail at how Spring fits into the picture.
After defining both and looking at Spring's relationship with them, we will explore the concepts
that are essential to Spring's implementation of DI. This chapter covers only the basics of Spring's DI
implementation; we discuss more advanced DI features in Chapter 5 and look at DI in the context of
application design in both Chapters 5 and 12. More specifically, this chapter will cover the following
topics:
Inversion of Control concepts: In this section, we discuss the various kinds of IoC
including Dependency Injection and Dependency Lookup. This section looks at
the differences between the various IoC approaches and presents the pros and
cons of each.
Inversion of Control in Spring: This section looks at IoC capabilities available in
Spring and how these capabilities are implemented. In particular, this section
looks at the Dependency Injection services that Spring offers, including Setter
Injection, Constructor Injection, and Method Injection.
Dependency Injection in Spring: This section looks at Spring's implementation
of the IoC container. For bean definition and DI requirements, BeanFactory is
the main interface an application interacts with. However, other than the first
few samples, all the rest of the sample codes provided in this chapter will focus
on using Spring's ApplicationContext interface, which is an extension of
BeanFactory and provides much more powerful features than enterprise
applications would require. We will cover the difference between BeanFactory
and ApplicationContext in later sections.
Configuring Spring application context: The final part of this chapter focuses on
using both the XML-based configuration and the Java annotation approach for
the ApplicationContext configuration. This section starts with a discussion of
DI configuration and moves on to look at additional services provided by
BeanFactory (part of Spring's ApplicationContext) such as bean inheritance,
life-cycle management, and autowiring.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home