Learn Java for Web Development

(Tina Meador) #1

206 CHAPTER 5: Building Java Web Applications with Spring Web MVC


Note The core of the Spring Framework is based on the principle of Inversion of Control (IoC) that provides
injection of dependencies. However, Spring is not the only framework offering dependency injection
features; there are several other frameworks such as Seam^8 , Google Guice^9 , and JEE6 and newer that offer
dependency injection.

POJO Objects

Configured Objects

Configuration Metadata Spring loc
Container

Figure 5-1. Spring IoC container


At the time of writing, Spring 3.2.2 is expected to be released; Spring 3.1 was released in
December 2011. Spring Framework 4.0 is expected by the end of 2013, with plans to support Java
SE 8, Groovy 2, and some aspects of Java EE 7.


Spring Framework Fundamentals


An application is composed of components such as web components and business logic
components. These components need to collaborate with each other to fulfill the common business
goals of the application, so these components depend on one another. This dependency, if uncontrolled,
often leads to tight coupling between them, resulting in an unmaintainable application. Controlling
this coupling so that it does not result in a tightly coupled application is a nontrivial task. By
contrast, if a component of the application does not depend on another component, it will not have
to look for it, all the components will be fully isolated, and the resulting application will be loosely
coupled. But such an application will not do anything. Essentially, components should depend on
other components but should not look for these components on which they depend. Instead, such
dependencies should be provided to the dependent components. This is the essence of Inversion of
Control. The Spring Framework is one such IoC framework, which provides the dependencies to the
dependent components by means of dependency injection.


(^8) http://www.seamframework.org/
(^9) http://code.google.com/p/google-guice/
(^10) http://martinfowler.com/bliki/InversionOfControl.html
Note IoC is based on the Hollywood principle^10 : “Don’t call us; we’ll call you.”
Figure 5-1 is a high-level view of how Spring works.

Free download pdf