Spring Tutorial Home

  • Managing Database Transactions
  • Remoting in Spring
  • Working with the Web Layer

Spring Home

Java Resources

Community

Site

"http://www.w3.org/TR/html4/loose.dtd">







Wiring Beans Introduction


In Spring applications objects are not responsible to creating the dependent objects to do their job. It is the responsibility of the Spring
container. The container will create the objects, wire
them together, configure them, and manage their complete lifecycle. Spring's container uses
dependency injection (DI) to manage the components that make up an application.
This includes creating associations between collaborating components. As

such, these objects are cleaner and easier to understand, support reuse, and are
easy to unit-test.


Traditionally,
each object is responsible for obtaining its own
references to the objects it collaborates (Dependencies). So the hard coupled code is created which is very hard to test as we need to create all dependencies in order to test any object. Whereas in Dependency Injection, objects are given their
dependencies at creation time by some external mainly XML file and the container itself will take care of
collaborating objects while creating any object in the application. The key benefit of DI is loose coupling. Dependency injection was commonly referred to as inversion of control (IOC).


The coming sections will discuss how to instantiate Spring containers i.e. BeanFactory and ApplicationContext in the first section. Later, we will discuss how do we configure and wire the bean together and how the spring container will take care of object creation as per the given
dependencies in the spring-beans.xml file.


 




                    

Copyright © 2010 VisualBuilder. All rights reserved