Search This Blog

Thursday 1 May 2014

Spring Container

Spring Container

It offers approach to configure and manage java objects using refelection. Spring Container is responsible for control object lifecycle by calling their initilization methods.

Objects created by spring container are called managed objects or beans.

Spring container responsible assemble beans which are configured in the context.

The container gets the information to instantiate objects, configure and assembling by reading beans configuration metadata.

Configuration metadata is represented in XML or java annotation. It allows you to express objects that compose your application and inter-dependencies between objects.

BeanFactory & ApplicationContext interfaces provides a way for accessing spring container.

Spring provides several modules like CORE, WEB, MVC, JDBC, AOP,J2EE...etc.


There are three different containers in spring.

FileSystemXmlApplicationContext ,ClassPathXmlApplicationContext – These spring containers used by stand
alone applications.
 
FileSystemXmlApplicationContext : Reads beans configuration from file system,
 so needs to provide exact path of the XML file.
 

ClassPathXmlApplicationContext: Reads beans configuration from class path.
 
Example:
=======
ApplicationContext ctx = new FileSystemXmlApplicationContext("X://com/xyz/beans.xml");
 
ApplicationContext ctx = new ClassPathXmlApplicationContext("/com/xyz/beans.xml");

WebApplicationContext - This spring container used by web applications and server manages this application context

Note: Spring creates a one singleton bean instance per context.
In the above case one singleton bean instance per File System Context and another per Class Path Context.

Similarly if you are going to create context multiple times with either File System Context or Class Path Context, then also spring creates multiple singleton bean instances per context object.