2. Spring and Dependency Injection
● Spring is an open source framework, created
by Rod Johnson and described in his book
Expert One-on-One: J2EE Design and
Development
● Dependency injection-Spring promotes loose
coupling through a technique known as
dependency injection(DI)
3. Spring and Dependency Injection
● Coupling is a two-headed beast. On one
hand, tightly coupled code is difficult to test,
difficult to reuse, difficult to understand, and
typically exhibits "whack-a-mole" bugs.
4. Spring Basics
● Any Java Application can benefit from Spring
in terms of simplicity, test-ability, and loose
coupling.
● What's more, Spring is non intrusive: objects
in a Spring-enabled application often have
no dependencies on Spring-specific classes.
5. Spring Basics
● At the core of Spring Framework is the
Spring container.
● Spring's core container provides the
fundamental functionality of the Spring
Framework. BeanFactory
● In Spring, there are many ways to wire
components together, but the most common
approach is via XMLs.
6. Basic Bean Writing
● The act of creating these associations
between application objects is the essence
of dependency injection (DI) and is
commonly referred to as wiring.
● Containing your beans
● In Spring-based application, your application
objects will live within the Spring container.
7. Basic Bean Writing
● The container is at the core of the Spring
Framework. Spring's container uses
dependency injection (DI) to manage the
components that make up an application.
● Two types of Spring containers
● Bean factories
● Application contexts
8. Introducing the BeanFactory
● Bean factory is an implementation of the
Factory design pattern. That is, it is a class
whose responsibility is to create and
dispense beans.
● Bean factory is a general-purpose factory,
creating and dispensing many types of
beans.
9. Introducing the BeanFactory
● Beans are "lazily loaded" into bean factories,
meaning that while the bean factory will
immediately load the bean definitions (the
description of beans and their properties),
the beans themselves will not be instantiated
until they are needed.