In this tutorial we will learn Spring framework from the beginning.Like,many other J2ee frameworks Spring is also a J2ee framework to build j2ee application. To understand Spring, one has to have idea about Java programming language and XML. All the examples of this tutorial has been developed by using Eclipse IDE. So, familiarity of Eclipse or MyEclipse IDE is required but not mandatory. Spring depends on XML configuration files so you should have basic level idea of XML.
What is Spring?
Spring is a lightweight, loosely coupled open source framework used for developing enterprise application.
- Lightweight - Spring is lightweight since each spring module is independent in itself. We are free to choose the modules we want. For example we can use Spring JDBC and skip spring MVC altogether.
- Loosely Coupled - Spring is a framework for Dependency Injection and thus promotes loose coupling.
History of Spring
Spring came after EJB.The first specification of EJB was released in 1998. This specification required the developer to create many interfaces and configuration files which was awkward and error prone. Another major drawback of the then EJB specification was its tight coupling on containers. This prevented POJO based development difficult.
The first version of spring, released in 2003 by Rod Johnson, aimed to address these complexities of EJB by encouraging POJO oriented development.
Advantages of Spring:-
- Application Server not required:- Spring based application can be deployed in web containers like Tomcat. Application Servers like Weblogic,Websphere are not mandatory for Spring application deployment.
- Modular Approach:- The whole framework is divided in smaller modules like Spring Core, Spring MVC,Spring JDBC,Spring OXM etc. But, developers generally use what is required. The modules which are not relevant to the current project scope are not required to use.
- Usage of other frameworks:- Spring uses other popular open source frameworks where ever requires like Hibernate,JMS,Quartz etc. So, it's like many frameworks inside one framework.
- POJO Based:- Spring depends on POJO based development. Since, it is simpler approach. It is easy to maintain and test. Implementation of popular Spring features like Dependency Injection has got possible only because of its POJO model.
- Annotation Based:- Spring uses annotations. So, it's easy for developers and easily maintainable.
- XML Configuration:- Spring is XML based. So, it's easy to maintain and understand.
- REST Support:- Spring supports easy creation of Restful web services.
- Aspect Oriented Programming Approach:- Spring follows aspect oriented programming approach. For this reason implementation of common features like logging has become much easier in Spring.
- Usage of Maven:- It's a common practise to use Maven in Spring application. Spring provides support for Maven usage in applications. Although, Spring application can be built using ANT. But, it's a general practise to use Maven. Since, Spring depends on lot of third party libraries. Since, maven is used developers don't have to download all the libraries of their own.