Spring Tutorial

Spring framework has become a default standard in building any enterprise-level Java application. In this spring tutorial, we will learn the core concepts of the spring framework and how to use it to build an application with a real-life web application.

Spring is an open-source framework developed by Rod Johnson in 2003. This framework provides many features in terms of simplicity, testability and loose coupling. Spring mostly empowers Plain Old Java Objects (POJO) which is referred to as beans to achieve things that were previously only possible with Enterprise Java Beans (EJBs).

Spring Framework Advantages

One of the main advantages of Spring is, it is lightweight and minimally invasive. When I say invasive, it means Spring tries to avoid littering your application with its own APIs. You may have to annotate one of the Spring annotations, but it is mostly your own POJO.

Spring also offers loose coupling of components within the application such that, the object just states their dependency instead of creating and looking for dependent objects. It is the responsibility of spring to provide dependent objects to each component. Spring also allows developers to focus on only the core logic of application by taking care of boilerplate configurations and code.

In the last few years, spring’s popularity is booming. A lot many enterprise-level projects are using the spring framework as their core framework. Important to mention many other spring projects is using this framework as a foundation to provide additional functionalities to developers for quick development.

Spring Framework is built by combining various modules. Each module has its own functionality. There are around 20 modules as such which are grouped into different heads like – Core Container, AOP, Web, Test, etc.

spring-architecture-diagram
Source: Screenshot from Spring in Action

These modules give you everything you need to develop an enterprise-ready application. Having said that, you don’t require to base your application completely in Spring. You have the liberty to choose whichever module which fits your need.

Let’s look into these spring modules one at a time and understand what they do.

Core Spring Container

The heart of spring is a container that manages how the beans in an application are created, configured, managed and destroyed. These modules provide the fundamental parts of the framework. It comprises of BeanFactory and Application Context which provides the Inversion of Control (IOC) and Dependency Injection (DI) feature. All of the spring modules are built on top of the core container.

Spring’s AOP Module

With Aspect-Oriented Programming (AOP), application-wide concerns like logging, authentication, security, etc. are decoupled from the objects to which they are applied. With AOP, you define the common functionality in one place, and you can declaratively define how and where this functionality is applied without having to modify the class to which you’re applying the new feature.

Data Access and Integration

When you work with JDBC, it results in a lot of boilerplate code lingering around in your application like getting a connection, creating a statement, processing a result set and then closing a connection. This module abstracts these boilerplate codes so that your database code is clean and simple and you can focus only on the core logic.

Web and Remoting

Model-View-Controller (MVC) paradigm is an accepted approach to build any web application so that, the user interface is separate from the core application logic. Spring provides a feature to build an MVC application with less hassle. Do not worry too much about it if this is too overwhelming. We will discuss Spring Boot in the future which is a simplified project offered by Spring to build web applications quickly.

Testing

As a Java developer, we know how important is to test our individual code. Spring understands this importance and provides a dedicated module to test spring applications. There are collections of mock implementations for writing unit tests against the code that works with databases, REST calls, servlets, etc. Throughout this spring tutorial, many of the examples will be driven by test and utilizing the testing facilities offered by spring.

This was just a brief summary of what the spring framework has to offer. We will be covering a lot more going forward in this spring tutorial. We will be learning how to build a real-life application using spring and other components. But before we go into that it is important for us to understand the core concepts of spring. So please stay with me. I am sure by the end of this spring tutorial you will start connecting the dots and become the next expert in build application using spring framework.

As part of this Spring Tutorial series, we will be learning the concepts in phases. Bombarding you advance concepts of Spring or Spring Boot doesn’t make sense if you don’t have a grip on fundamental concepts of Spring Core. So please check out the following posts as part of this series: