Spring Framework - Overview


Spring framework is an open-source and lightweight framework for developing robust Java applications in a quiet and comprehensive manner with less amount of time. It is also considered as a framework of frameworks because of its supports to a variety of frameworks such as Tapestry, EJB, JSF, hibernate, struts, etc;

First written by Rod Johnson, The Spring tutorial was released under the Apache 2.0 license back in 2003. The Spring framework’s basic version is around 2MB. The basis of the Spring Tutorial is its version 4.1.6 that was released in March 2015 for which it is written.

The popularity of the Spring tutorial is such that millions of people around the globe use it to create an excellent, high-performing, reusable code with ease of testing. The Spring Framework consists of various modules that are IOC, AOP, DAO, Context, ORM, WEB MVC, etc.

Inversion Of Control (IOC) and Dependency Injection

Inversion of control and dependency injection are the design patterns used to eliminate dependency from the code of programming. It is an easier and convenient way to test the code as well as to maintain it. Now look at the code below for a clear and better understanding:-

class Employee{  
Address address;  
address=new Address();  

In the above code, we can find the dependency between the Employee and Address (in tightly coupled), While in the Inversion of control, the same will look like following:-

class Employee{  
Address address;  
Employee(Address address){  

IOC just makes the code loosely coupled. The benefit of this is that you need not modify the code if the logic is changed. With the above coding and illustration we came to know that in the Spring framework, the use of the IOC container is used to inject the dependency. The metadata that is provided to the IOC container can be done either by XML file or annotation.

Benefits of Dependency Injection

Spring Framework Advantages

  • Since the Spring framework provides templates for JDBC, Hibernate, JPA, etc, the use of long coding is no longer required as it hides some initial or basic steps of these technologies. You just need to write the code of the query that is being executed. Thus, it saves a lot of time. One such example is the use of the JDBC template, with this there is no need to write the code for exception handling.
  • With the use of dependency injection, you can get loosely coupled code that can be maintained easily. This is an exceptional feature under Inversion of Control (IOC). With the Dependency Injection, you can test the code easily.
  • The Spring framework also enables us to test the application easily because of the environment-dependent code that comes with this framework. Also it becomes easier to use dependency injection for injecting test data.
  • Spring Framework is lightweight that makes it easy to use. The functionality of POJOs make it a non-invasive framework for the application development as there is no need to inherit any class or implement any interface.
  • Developing the JavaEE applications faster and easier in the Spring framework since it uses dependency injection and its support to various frameworks.
  • A major component of Spring is the Aspect Oriented Programming (AOP) framework which allows you to clearly decouple code. It also lets you decouple cross-cutting concerns from the affected objects.
  • You can organize a Spring framework in a modular way. Although its number of packages and classes comes in the substantial category, all you have to think about are those you need and ignore the rest of them.
  • Spring framework lets you develop enterprise-class applications by the use of POJOs. With POJOs, you don’t need to use an EJB container product like an application server but you can use a servlet container like Tomcat or its equivalent.
  • Spring framework is not the sole framework for its other counterparts; it uses some of the existing frameworks like ORM, logging frameworks, JEE, Quartz, JDK timers, as well as other view technologies.
  • It is easy to test a Spring application because it uses environment-dependent code. You can also use the dependency injection to inject test data by using JavaBeanstyle POJOs
  • Spring's web framework is an exceptional and well-designed web MVC framework that is so often used to its counterparts or equivalents like the least popular web frameworks such as Struts or others.
  • In the Spring framework, you can use an easy Application Programming Interface (API) to translate technology-specific exceptions into consistent, unchecked exceptions.
  • Spring framework uses lightweight IoC containers that are just different from the EJB containers that come in the heavy category. With the lightweight containers, it is very convenient to develop and deploy applications on computer systems with a limited amount of memory and CPU resources.
  • Spring framework provides a transaction management interface that is consistent and scalable to a local transaction. Further, it can also be scaled to global transactions.