Hello Friends,
This blog help us to understand basic feature and may give you an answer of question “Why I should use Spring framework in my development?”.
History: Friends when you start learning any new thing, I would say start with the history and purpose of it.
- Rod Johnson is father of this framework,He has realised on June 2003.
- V 1.0 in March 2004
- V 2.0 in October 2006
- V 3.0 in December 2009
- V 4.0 in December 2013
I am presenting a Fantastic Four reasons/features with brief understanding of Spring framework.
1. Dependency injection or Inversion of Control.[ICO and DI]
"Don't worry about create an instance just ask me whenever you require it,another words It says do not need to create an object of a class into another class."
Ex.
class A {
function()
{
B bObj = New B();
}
}
Class A is completely depend on Class B : Modification of Class B may force you to modify Class A.
Ex. Change in name of methods or class name itself.
This is a simple example but in real time it may me much more complex then it looks.
To overcome with this problem,Spring came up with Dependency injection, with help of Spring-config.xml you can easily and effectively resolve this problem.
2.Aspect Oriented Programming :[AOP]
"It says do not mix business logic with non-business logic"
Ex.
class FindNumber {
// logger
try{
function callMe(a,b,c)
{
return a*b+c;
}
}
catch(Exception e)
{
//logger.error
}
//logger.info
}
Main purpose of this class is to find a number, but you can see there are lot of other things surrounding it, like logger, Exception handling etc..
We are simply mixing two things. [Functional + Non functional], we may increase our difficulty to mange our class in future.
It's not only logger we used to mix with our program but in real time there will be more like transaction management, cashing management etc and We will end up with a very confusing class which has plenty of line containing Non-functional as well functional.
AOP help us to overcome this problem which provides the solution which help us to keep non functional things out side the class.
3.Data access [JDBC,ORM,OXM,JMS,Transaction management]
- Opening and Closing database connection.
- Any exception handling code.
- Prepare and execute statement and result set.
- Converting Java Object to XML and Vice Versa.
- Fully support to integrate with JAXB, Castor etc..
-Provide support to produce and consume message.
Spring Transaction Management.
- The Spring Framework provides both declarative and programmatic transaction management. Most users prefer declarative transaction management, which is recommended in most cases.
- You write your code once, and it can benefit from different transaction management strategies in different environments.
4.Spring MVC
- Provide Complete MVC structure, Highly recommended in web designing and development.
- The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet
that dispatches requests to handlers, with configurable handler mappings
- The default handler is based on the @Controller
and @RequestMapping
annotations, offering a wide range of flexible handling methods.
Hope this will help you guys to understand spring at first look.
Let me know in case of any questions/queries.
Thanks,
Sagar Vyas