<bean id=”bean1" class=”bean11">
<property name=”game”>
<ref bean=”bean2"/>
<bean id=”bean2" class=”bean22" />

The IOC container

The mainstream JEE involves heavyweight containers
to develop applications. So exploring alternatives and
coming up with creative ideas have evolved a lot of open
source java communities. In the Java community there’s
been a rush of lightweight containers that help to assemble
components from different projects into a cohesive application. Several open source projects, including Spring, PicoContainer, and HiveMind use the IoC pattern to develop lightweight JEE Containers. The container manages the life cycle and configuration of application objects.

Spring should not, however, be confused with traditionally
heavyweight EJB containers, which are often large. The Spring actually comes with two distinct containers:

Bean Factories-defined by “org.springframework. beans.
factory.BeanFactory” are the simplest containers, providing support for dependency injection.

Application contexts
- defined by “org.springframework.
context.Application Context” provides application framework services.


Bean factory is an implementation of the factory design pattern. Its function is to create and dispense beans. As the bean factory knows about many objects within an application, it is able to create association between collaborating objects as they are instantiated. This emoves the burden of configuration from the bean and the client.

supports two object modes.

Singleton mode provides a shared instance of the object with a particular name, which can be retrieved on lookup. Singleton is the default and most often used object mode. It is ideal for stateless service objects.

Prototype mode ensures that each retrieval will result in the creation of an independent object. Prototype mode would be best used in a case where each user needed to have his or her own object. The bean factory concept is the foundation of Spring as an IOC container. IOC moves the responsibility for


making things happen into the framework and away from
application code. The Spring framework uses JavaBean
properties and configuration data to figure out which
dependencies must be set.

There are several implementation of BeanFactory like
which loads its beans based on the definition contained
in an XML file.


The Application Context is spring’s more advanced container. Like ‘BeanFactory’ it can load bean definitions, wire beans together and dispense beans upon request. Additonally, It also provides:

1. A means for resolving text messages, including support for internationalization ie. i18n messages

2. A generic way to load file resources.

3.Events to notify beans that are registered as listeners.

Because of additional functionality, ‘Application Context’
is preferred over a BeanFactory. BeanFactory is
used for simple applications and when the resource is
scarce like mobile devices.

III Service Abstraction Layers

Spring provides consistent integration with various standard and 3rd party APIs through its various Service abstraction layers. Few of them are:

1. Transaction Management abstraction for JTA, JDBC, others
2. Data Access abstraction for JDBC, Hibernate, JDO, TopLink, iBatis
3. Abstraction for Emailing
4. Remoting abstraction layers for EJB, Web Services, RMI, Hessian/Burlap

Benefits of the Service Abstraction Layers in spring framework:

1. There is no implicit contract with JNDI, etc.
2. It separates the user from the underlying APIs.
3. It enhances the reusability to a great extent.
4. Spring abstractions always consist of inter faces.
5. Testing is kept simpler than ever before.
6. For data access, Spring uses a generic transaction infrastructure and DAO exception hierarchy that is ommon across all sup ported platforms.

July 2007 | Java Jazz Up |26
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 ,            Download PDF