Spring

Spring Framework


 What is framework.
A framework is a semi finish application  which provides  abstraction layer on core technologies by providing common feature and tell us to develop the business specific logic.In otherwords it says you should concentrate the common functional-ties which is required for every application ,you should concentrate upon the business specific functional-ties which different for different application.


A simply a framework is software applcation which helps the programmer not to write the common functionlites.A framework is responsible for providing common functionalites.

 Some common functionalities are..

  • Creating jdbc driver class object..
  • Creating connection object ..
  • Creating statement object
  • Forwarding  or including the request  dispatcher object.



 Framework provides  above the common functionalites by through xml configuration file automatically to our application.

                                                                            Spring


Spring is the open source framework to developed to web based or enterprises based distributed application
.Spring is called the framework of framework as it provides abstraction layer on core technologies as well as on  the framework.It is the master of all Java based J2ee framework.

Spring Feature.

  • It is the light weight based framework as its application can be executed without any web server or applcation server.
  • Spring provides a most important feature called dependance injection.
  • Spring application can be devloped with POJO(plane old java object) and POJI(plance old java interface).
  • With spring we can developed the entire project without needing of any other framework.
  • Spring provied abstraction layer ORM technlogies like Hibernate,IBatis,TopLink,JPA
  • Spring provides a  technlogy called Spring MVC whic is a alternate of Strus  and Jsf.
  • Spring provides a big feature called  AOP(Aspect Oriented Programming) for tranaction management
  • Spring provied annotation based application for providing metadata ..
  • Spring provides abstarction layer on EJB and Web services
Spring is the most usable framework in market because of its flexibilities and maintain-abilities.  
Spring contains following module.

  •     Spring Core Module
  •     Spring Context [ J2EE ]
  •     Spring DAO Module [ Spring JDBC ]
  •     Spring ORM module
  •     Spring AOP [ Aspect Oriented Programming ]
  •     Spring WEB-MVC Module

The most important module of spring is Spring Core or Spring IOC.

Although the entire project can be developed by spring,spring is famous for dependency injection and for providing Aspect oriented programing.

Spring Core

Dependancy Injection

Spring container is responsible for injecting the dependency object to dependant object based on the configuration done in spring configuration file.

Spring Core has been devloped by implementing the IOC(inversion of control) design pattern.In otherwords IOC design pattern has been implemented by spring to provides dependency injection.

A inversion of controller is a design pattern in which the the dependencies  object will be pushed  to the dependant object .

Spring uses IOC design pattern for implementing dependency injection and is the alternate for dependency look-up which was being used in EJB 2 application.
A dependency look-up is design pattern in which dependent object has to search or find or look up   the dependant  object  from the repository where the  the actual dependency object has been the bound with nickname.
The process in which dependent object has to search the dependency object  from repository based on the nick name  is called dependency look-up or unbinding.Here we are responsible to find the object and we have to make effort to find.


The process in which  the dependency object will be pushed or injected to the dependent object by the container is called dependency injection.Here container is responsible to inject or push the object





Type of injection

There are three types of Dependency Injection in spring.
  • Setter injection
  • Constructor injection
  • Interface injection

Setter Injection

It is the type of dependency injection in which the dependency object will be injected to the dependent reference via setter method.
To perform setter based injection there should be a property tag under the bean tag in the spring configuration file.
A snapshot of Setter injection.

In your java class.

HelloBean bean;
public void setBean(HelloBean bean)
{
this.bean=bean;
}
and in our spring configuration file..

<bean id="db" class="com.spring.DemoBean">
<property name="bean" ref="bn"/>
</bean>
<bean id="bn" class="com.spring.HelloBean"/>

Here setter method and property tag specifies that it is setter method injection.
Here DemoBean object is depend up the HelloBean object as dependency and is going to be injected to setter method via "ref" tag of DemoBean class.

 Constructor Injection

It is the type of dependency injection in which dependency object will be injected to the dependent reference via constructor.
To perform constructor based injection there should one argument constructor and a constructor-arg tag should be present under the bean tag in the corresponding spring configuration file.


HelloBean bean;
public  HelloBean(HelloBean bean)
{
this.bean=bean;
}
and in our spring configuration file..

<bean id="db" class="com.spring.DemoBean">
<constructor-arg >
<ref bean="bn"/>
</constructor-arg>
</bean>
<bean id="bn" class="com.spring.HelloBean"/>

Here the HelloBean object is injected to the HelloBean one argument  constructor  as dependency to the dependent HelloBean reference via constructor-arg tag.

Interface Injection

It is the type of dependency injection in which the dependency object will be injected to the dependent reference by implementing a interface.In otherwords by implementing a interface we can implement interface injection and it is not required to configure anything in the spring configuration file for injecting.

ex.
class MySpring implement IntializingBean

public void afterPropertiesSet()
{
code......
}
Here we can achieve interface injection by implementing any predefined interface only.There is no explicit configuration is required in spring configuration file.  




1 comment: