AOP and IoC

The subelement <value> sets the ‘name’ property by calling the set method as setName(“amit”); This process is called setter injection.

constructor injection : For constructor injection, we use constructor with parameters as shown below:

public class nameBean {
String name;
public nameBean (String a) {
name = a;

We will set the property ‘name’ while creating an instance of the bean ‘nameBean’ as

nameBean bean1 = new nameBean(“amit”);

Here we use the <constructor-arg> element to set the the property by constructor injection as:

<bean id=”bean1" class=”nameBean “>
<value>Bean Value</value>

To set properties that reference other beans <ref>, subelement of <property> is used as shown below:

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

The IOC containers 

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 fromdifferent 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.

 Let’s see how Spring container implements the IoC concepts 

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

1. Bean Factories - defined by “ o r g . s p r i n g f r a m e w o r k beans.factory.BeanFactory” are the simplest containers, providing support for dependency injection.

2. Application contexts - defined by “org.springframework.context. ApplicationContext” provides the application framework services. 

Configuration metadata 

As can be seen in the above image, the Spring IoC container consumes some form of configuration metadata; this configuration metadata is nothing more than how you (as an application developer) inform the Spring container as to how to “instantiate, configure, and assemble [the objects in your application]”. This configuration metadata is typically supplied in a simple and intuitive XML format. When using XML-based configuration metadata, you write bean definitions for those beans that you want the Spring IoC container to manage, and then let the container do it’s stuff.


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

Nov 2007 | Java Jazz Up | 8
View All Topics
All Pages of this Issue
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,

, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69   Download PDF