Tuesday, September 12, 2017

Spring Introduction and IOC


Spring

developed by Rod Johnson in 2003Spring Framework
Spring is a lightweight framework. It can be thought of as a framework of frameworks because it provides support to various frameworks such as Struts, Hibernate, Tapestry, EJB, JSF etc. 
The framework, in broader sense, can be defined as a structure where we find solution of the various technical problems.



Advantages of Spring Framework

Predefined TemplatesLoose CouplingEasy to testLightweightFast DevelopmentPowerful abstractionDeclarative support


Modules:

Core, Beans, Context, Expression Language
AOP, Aspects and Instrumentation
Data Access / Integration
JDBC, ORM, OXM, JMS and Transaction modules.
Web, Web-Servlet, Web-Struts and Web-Portlet.
Spring batch








IoC Container

The IoC container is responsible to instantiate, configure and assemble the objects. The IoC container gets informations from the XML file and works accordingly. 
The main tasks performed by IoC container are:
to instantiate the application classto configure the objectto assemble the dependencies between the objects


There are two types of IoC containers. They are:

BeanFactory

ApplicationContext
Resource resource=new ClassPathResource("applicationContext.xml");  BeanFactory factory=new XmlBeanFactory(resource);  

Bean Factory

Bean instantiation/wiring
Application ContextApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");      Bean instantiation/wiringAutomatic BeanPostProcessor registrationAutomatic BeanFactoryPostProcessor registrationConvenient MessageSource access (for i18n)ApplicationEvent publication

<beans      xmlns="http://www.springframework.org/schema/beans"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:p="http://www.springframework.org/schema/p"      xsi:schemaLocation="http://www.springframework.org/schema/beans                 http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">   

Dependency Injection in Spring

Dependency Injection (DI) is a design pattern that removes the dependency from the programming code so that it can be easy to manage and test the application. Dependency Injection makes our programming code loosely coupled
Two ways to perform Dependency Injection in Spring framework
Spring framework provides two ways to inject dependency

By Constructor

<bean id="e" class="com.Employee">  <constructor-arg value="" type=""></constructor-arg>  </bean>  


By Setter method

<bean id="employee" class="com.bebo.Employee">  <property name="name" value="Anil Thakur"></property>  </bean>

No comments:

Post a Comment