IoC
Inversion of Control also known as Dependency Injection (DI). It is a process whereby objects define their dependncies by
1) Constructor arguments
2) Arguments to factory methods
3) Properties which are set on the object after it is constructed or return from factory method.
The container then injects the dependencies when it creates the bean. This process is fundamentally Inverse where bean controls the instantiation of its dependencies by instantiating them of using the Service locator patterns.
The org.springframework.beans, org.springframework.context are the basis for spring IoC container. The BeanFactory interface provides advanced configuration mechanism capable of managing any type of object. ApplicationContext is sub-Interface of it. which adds:
1) Easier Integration with Spring's AOP features
2) Message Resource Handling (for Use in Internationalization)
3) Event Publication
4) Application-layer specific contexts such as (WebApplicationContext)
i. e BeanFactory provides more configuration and basic functionality and ApplicationContext adds Enterprise level functionality.
In Spring, the Objects that form backbone of the application and are managed by the spring's IoC container are called beans. A bean is and Object with is created, assembled and managed by the spring IoC container. Beans, and dependencies among them are reflected by the configuration metadata which is used by the Spring Container.
Container Overview
-----------------------
The org.springframework.context.ApplicationContext represents the Spring's IoC Container. It is responsible for Instantiating, configuring and assembling the beans. It gets instruction on how to Instantiate, configure and assemble the beans from configuration Metadata. Configuration metadata can be provided using XML, Java Configuration or Java Code.It lets you express the compose of the objects which reflects your application.
Several implementations are provided for the ApplicationContext. For stand-alone applications we can created a container by instantiating ClasspathXmlApplicatonContext or FileSystemXmlApplicationContext.While you can Instruct the spring to read the configuration metadata using XML as treditional format, You can also enable the Annotation based or code based configuration metadata by supplying declarative instruction to enable the support for those types as well.
The following diagram shows high level view of spring framework, Your application classes are combined with configuration metadata, so that, once the ApplicationContext object is instantiated, You have fully configuration executable application.
Configuration Metadata
----------------------------
As the above diagram shows, the configuration metadata is the instructions you want to tell to spring on how to Instantiate, configure and assemble the objects of your application.Configuration metadata is traditionally supplied in XML format.
The other forms of metadata configuration supported are Annotation-based configuration and Java Based configuration.
configuration metadata consist of at least one and typically more than one bean declaration to be managerd. XML based configuration configures the bean using element under the top-level element. Java configuration configures the bean using @Bean annotation in the metadata class file annotated with @Configuration.
The following structure show a sample XML based configuration metadata
1) "id" is the individual identification for the beans
2) "class" Fully qualified classname of the object to be managed by IoC.
Instanticating Container
-----------------------------
The location path or paths supplied as the constructor arguments are the resource settings used as configuration metadata for ApplicationContext to create IoC container.
ApplicationContext context = new ClasspathXmlApplicationContext("services.xml", "dao.xml");
eg: service.xml, dao.xml
In the preceding example the the linkage between id and ref attribute refers to the collaborating objects.
Composing XML based configuration Metadata
----------------------------------------------------------
It is a best to have multiple bean definitions span into multiple XML configurations based on their logical layer or module. You can use these files as Resources in constructor parameters while constructing an application constents. Alternatively, you can use multiple element having resource attribute locating to the path of dependent resource files with in the element.
Inversion of Control also known as Dependency Injection (DI). It is a process whereby objects define their dependncies by
1) Constructor arguments
2) Arguments to factory methods
3) Properties which are set on the object after it is constructed or return from factory method.
The container then injects the dependencies when it creates the bean. This process is fundamentally Inverse where bean controls the instantiation of its dependencies by instantiating them of using the Service locator patterns.
The org.springframework.beans, org.springframework.context are the basis for spring IoC container. The BeanFactory interface provides advanced configuration mechanism capable of managing any type of object. ApplicationContext is sub-Interface of it. which adds:
1) Easier Integration with Spring's AOP features
2) Message Resource Handling (for Use in Internationalization)
3) Event Publication
4) Application-layer specific contexts such as (WebApplicationContext)
i. e BeanFactory provides more configuration and basic functionality and ApplicationContext adds Enterprise level functionality.
In Spring, the Objects that form backbone of the application and are managed by the spring's IoC container are called beans. A bean is and Object with is created, assembled and managed by the spring IoC container. Beans, and dependencies among them are reflected by the configuration metadata which is used by the Spring Container.
Container Overview
-----------------------
The org.springframework.context.ApplicationContext represents the Spring's IoC Container. It is responsible for Instantiating, configuring and assembling the beans. It gets instruction on how to Instantiate, configure and assemble the beans from configuration Metadata. Configuration metadata can be provided using XML, Java Configuration or Java Code.It lets you express the compose of the objects which reflects your application.
Several implementations are provided for the ApplicationContext. For stand-alone applications we can created a container by instantiating ClasspathXmlApplicatonContext or FileSystemXmlApplicationContext.While you can Instruct the spring to read the configuration metadata using XML as treditional format, You can also enable the Annotation based or code based configuration metadata by supplying declarative instruction to enable the support for those types as well.
The following diagram shows high level view of spring framework, Your application classes are combined with configuration metadata, so that, once the ApplicationContext object is instantiated, You have fully configuration executable application.
Configuration Metadata
----------------------------
As the above diagram shows, the configuration metadata is the instructions you want to tell to spring on how to Instantiate, configure and assemble the objects of your application.Configuration metadata is traditionally supplied in XML format.
The other forms of metadata configuration supported are Annotation-based configuration and Java Based configuration.
configuration metadata consist of at least one and typically more than one bean declaration to be managerd. XML based configuration configures the bean using
The following structure show a sample XML based configuration metadata
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
id="..." class="...">
id="..." class="...">
1) "id" is the individual identification for the beans
2) "class" Fully qualified classname of the object to be managed by IoC.
Instanticating Container
-----------------------------
The location path or paths supplied as the constructor arguments are the resource settings used as configuration metadata for ApplicationContext to create IoC container.
ApplicationContext context = new ClasspathXmlApplicationContext("services.xml", "dao.xml");
eg: service.xml, dao.xml
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
id="petStore" class="org.springframework.samples.jpetstore.services.PetStoreServiceImpl">
name="accountDao" ref="accountDao"/>
name="itemDao" ref="itemDao"/>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
id="accountDao"
class="org.springframework.samples.jpetstore.dao.jpa.JpaAccountDao">
id="itemDao" class="org.springframework.samples.jpetstore.dao.jpa.JpaItemDao">
In the preceding example the the linkage between id and ref attribute refers to the collaborating objects.
Composing XML based configuration Metadata
----------------------------------------------------------
It is a best to have multiple bean definitions span into multiple XML configurations based on their logical layer or module. You can use these files as Resources in constructor parameters while constructing an application constents. Alternatively, you can use multiple
resource="services.xml"/>
resource="resources/messageSource.xml"/>
resource="/resources/themeSource.xml"/>
id="bean1" class="..."/>
id="bean2" class="..."/>