What is the Spring Framework?

The age-old answer to this question is, “Spring is a Dependency Injection Framework”. In reality, it is much more than that.

Spring is the most popular Java Enterprise application development framework, it comes with many tools and libraries to solve almost any problem in the java world. May it be microservices or a simple database-driven enterprise application, Spring has the necessary tools to get you started. It is difficult to explain all the features and libraries available in Spring-stack at this moment, you will get to know them all as you progress.

You have come across 2 new keywords, Dependency and Dependency Injection, so let us understand them one by one.

What is Dependency Injection?

Dependency Injection is a technique in which a class is made independent of its dependencies. This is basically decoupling the Objects from their creation. I will explain this with an example.

In the code below, PDFReader needs an object of FileProcessor. The PDFReader has a direct dependency on FileProcessor class, this is a tight coupling between the 2 Classes.

PDFReader.java
public class PDFReader {
  private FileProcessor fileProcessor;
  
  public PDFReader(){
    this.fileProcessor = new FileProcessor();
  }
}

We can rewrite the above class to loosely-coupled classes like the below code where FileProcessor is passed in the constructor. This way of implementing code is known as dependency injection.

PDFReader.java
 public class PDFReader {
  private FileProcessor fileProcessor;

  public PDFReader(FileProcessor fileProcessor){
    this.fileProcessor = fileProcessor;
  }
}

Further reference: Stackoverflow thread on Inversion of Control and Dependency Injection.

History of Spring Framework?

Spring was originally catered as a simple and lightweight alternative to J2EE. Back in days, J2EE was suffering from bad performance issues and difficult to use by the developers. This is how the Spring Framework was born in the Java community.

  • Spring came into being in 2003 as a response to the complexity of early J2EE specification.
  • It is not a replacement, but a complementary to Java EE.
  • Spring integrates with the carefully selected Java EE specifications. Some of these specifications are listed below:
  • Spring also supports Dependency Injection (JSR 330) and Common Annotations (JSR 250) specifications.

Architecture Design Philosophy

It is always advisable to understand the design philosophy of any framework you use.

  1. Intuitive API design – Spring emphasizes meaningful API design which is powerful and easy to consume by the developers.
  2. Strong backward compatibility – Spring carefully managed to force a minimum breaking changes throughout its evolution.
  3. Accommodate Diverse Perspectives – Spring is highly configurable to best suit your application design and architecture.
  4. Provides choice at every level – Spring lets you defer design decisions, infrastructure concerns, and third party integration decisions, etc as late as possible.
  5. High code standards – Spring framework claims clean code structure with no circular dependencies between packages. It has meaningful, current and accurate JavaDoc.

Framework Core Modules

Spring Framework is composed of several modules, each of these modules consists of individual features. Based on the project need, you can use the necessary modules as a Maven/Gradle dependency.

Spring 4.x modules
Image source – Spring.io

Various Spring modules can be grouped together into the following categories.

  1. Spring Core modules – IoC Container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP.
  2. Spring Test modules – Mock Objects, TestContext Framework, Spring MVC Test, WebTestClient.
  3. Data Access Modules – Transactions, DAO Support, JDBC, O/R Mapping, XML Marshalling.
  4. Web Servlet modules – Spring MVC, WebSocket, SockJS, STOMP Messaging.
  5. Reactive Web modules – Spring WebFlux, WebClient, WebSocket.
  6. Integration modules – Remoting, JMS, JCA, JMX, Email, Tasks, Scheduling, Caching.

Spring 5.x language and Platform Supports

  • Languages Spring Supports – Kotlin, Groovy, Dynamic Languages.
  • Java EE – Minimum Java EE 7 and maximum Java EE 8
  • Spring work with JDK 8+, till JDK 11 LTS. Java 8 update 60 is suggested as the minimum.

Starting a Spring Project

If you are exploring Spring or starting a new project in Spring, then it is advisable to use Spring Framework by creating a Spring Boot based application.

You are advised to use, start.spring.io to generate the project. We will follow this step by step as you proceed with the Tutorial.

Spring Help Center

By |Last Updated: April 1st, 2024|Categories: Spring Framework|

Table of Contents