The Spring Framework

In this article, we will delve into the Spring Framework, which is widely recognized as one of the most popular frameworks for Java EE.

Spring framework architecture

  • Core components of Spring
  • Various projects under the spring framework umbrella.

When analyzing the Google Trends chart for Spring Framework, Servlet, JSP, and JSF, it is evident that Spring is significantly leading among all other Java EE technologies.

Spring Framework Popularity

Can you explain what the Spring Framework is?

The Spring framework, created by Rod Johnson, is widely used by developers worldwide for developing dependable and top-notch Java enterprise applications. It has emerged as a preferred alternative to the EJB model, making it possible to develop various types of applications.

The fundamental principles of Spring framework – Dependency Injection (DI), Inversion of Control (IoC), and Aspect-Oriented Programming (AOP).

  • It is impossible to understand what is Spring Framework without understanding what is Dependency Injection and Inversion of Control. Dependency Injection also called as DI, is one of the types of Inversion of Control (IoC).
  • Inversion of Control – this is the principle of object-oriented programming, in which objects of the program do not depend on concrete implementations of other objects, but may have knowledge about their abstractions (interfaces) for later interaction.
  • Dependency Injection – is a composition of structural design patterns, in which for each function of the application there is one, a conditionally independent object (service) that can have the need to use other objects (dependencies) known to it by interfaces. Dependencies are transferred (implemented) to the service at the time of its creation. This is a situation where we introduce an element of one class into another. In practice, DI is implemented by passing parameters to the constructor or using setters. Libraries that implement this approach are also called IoC containers.
  • Aspect oriented programming – a programming paradigm that allows you to distinguish cross-through (functional) functionality in application. These functions, which span multiple application nodes, are called cross-cutting concerns and these cross-cutting notes are separated from the immediate business logic of the application. In OOP, the key unit is the class, while in AOP, the key element is the aspect. DI helps to separate application classes into separate modules, and AOP helps to separate cross-cutting concerns from the objects they affect.

The architecture of the Spring Framework

spring framework architecture

Core components of the Spring Framework

The SpEL, Context, Core, and Beans are four modules included in the Core container of Spring. These modules can be described as the following:

    The SpEL module offers a robust expression language for manipulating objects while they are being executed. Context, which is built on Beans and Core, grants access to any object defined in the settings. The ApplicationContext interface serves as the main component of the Context module. Meanwhile, the Core module incorporates essential elements of the framework such as IoC and DI properties. Lastly, the Bean module handles the creation and management of Spring Beans, serving as the building block of the application context structure.

Web application development framework provided by Spring Framework.

The Web layer of the Spring framework encompasses components such as Web, Web-MVC, Web-Socket, Web-Portlet, and more.

    The Web module offers various functions like file downloading, web application creation, and rest web service. Web-MVC includes a Spring MVC implementation for web applications. Web-Socket enables communication between client and server using Web-Sockets in web applications. On the other hand, Web-Portlet provides a MVC implementation for the portlet environment.

Accessing data in the Spring Framework

The container responsible for Data Access/Integration incorporates JDBC, ORM, OXM, JMS, and the Transactions module.

    JDBC simplifies the process of connecting to a database by eliminating the need for developers to manually register repetitive code. Spring ORM integrates with popular ORMs like Hibernate and JDO, which are implementations of JPA. The OXM module connects objects with XML using XMLBeans, JAXB, etc. The JMS module handles the creation, sending, and receiving of messages. Transactions support transaction management for specific methods and POJOs.

Various Modules

Spring contains various essential modules in addition to AOP, Aspects, Instrumentation, Messaging, and Test.

    1. AOP utilizes aspect-oriented programming and enables the utilization of all AOP capabilities.

 

    1. The Aspects module integrates with AspectJ, another robust AOP framework.

 

    1. Instrumentation is accountable for facilitating class instrumentation and class loader operations that are employed in server applications.

 

    1. The Messaging module grants STOMP support.

 

    Lastly, the Test module enables testing through either TestNG or the JUnit Framework.

Features of Spring 5

Spring 5 introduced significant changes compared to Spring 4, and it offers several key attributes.

    1. Spring now supports the latest versions of Java (8, 9) and Java EE (7, 8), Servlet (4.0), Bean Validation (2.0), and JPA (2.2). I am glad to see that Spring is making efforts to incorporate the latest technologies.

 

    1. Logging has been improved with a new module called spring-jcl.

 

    1. File operations now utilize NIO 2 streams, resulting in improved performance.

 

    1. Spring MVC controller methods now support Reactor (3.1 Flux and Mono) and RxJava (1.3 and 2.1) as return values.

 

    1. Support for Kotlin, Project Lombok, and JSON Binding API as alternatives to Jackson and GSON has been added.

 

    1. Spring WebFlux introduces reactive programming capabilities to Spring.

 

    1. JUnit 5 is now supported.

 

    Functional programming can be achieved using Kotlin.

You have the option to explore Spring Projects in our GitHub Repository.

Sources: Spring’s Official Website, Documentation on Spring’s Reference

 

More Tutorials

Spring Component annotation(Opens in a new browser tab)

Spring MVC HandlerInterceptorAdapter and HandlerInterceptor.(Opens in a new browser tab)

Spring Boot CLI(Opens in a new browser tab)

One example of Spring REST XML and JSON(Opens in a new browser tab)

Interview Questions for Web Services – SOAP, RESTful(Opens in a new browser tab)

Leave a Reply 0

Your email address will not be published. Required fields are marked *