Spring overview


May 14, 2021 04:00 Spring


Table of contents


Overview

Spring is the most popular enterprise Java application development framework, with millions of developers from around the world using it to create good-performing, easy-to-test, reusable code.

The Spring Framework is an open source Java platform originally written by Rod Johnson and first released under apache 2.0 license in June 2003.

Spring is a lightweight framework with a base version that is only about 2 MB in size.

The core feature of the Spring framework is that it can be used to develop any Java application, but building a web application on the Java EE platform requires extension. The goal of the Spring framework is to make J2EE development easier to use and promote good programming practices by enabling POJO-based programming models.

Three-tier architecture

  • A Performance Layer Web Layer MVC is a design model of the Performance Layer
  • B Business layer service layer
  • C Persistence layer dao layer

Spring's excellent features

  • Non-intrusive: Objects in Spring-based applications can be non-reliance on Spring's API
  • Control inversion: IOC - Inversion of Control, which refers to the creation of objects to Spring. B efore using Spring, objects were created by our own new in the code. A nd after using Spring. Objects are created to the Spring framework.
  • Dependency Injection: DI-Dependency Injection, which means that dependent objects do not need to manually call the setXX method to set it up, but are assigned by configuration.
  • Face-oriented programming: Aspect Oriented Programming - AOP
  • Container: Spring is a container because it contains and manages the lifecycle of the app object
  • Componentization: Spring implements a complex application that combines simple component configurations. You can use XML and Java annotations to combine these objects in Spring.
  • One-stops: An open source framework for a variety of enterprise applications and an excellent third-party class library can be integrated on the basis of IOC and AOP (Spring itself provides SpringMVC for the performance layer and Spring JDBC for the persistence layer)

Benefits of using the Spring framework

The main benefits of using the Spring framework are listed below:

  • Spring enables developers to use POJOs to develop enterprise-class applications. The advantage of using POJOs only is that you don't need an EJB container product, such as an application server, but you can choose to use a robust servlet container, such as Tomcat or some commercial products.
  • Spring is organized in a unit pattern. Even if the number of packages and classes is very large, you just have to worry about what you need and what else you can ignore.
  • Spring won't let you do the repetition in vain, it really leverages some existing technologies, such as ORM frameworks, log frameworks, JEE, Quartz, and JDK timers, and other view technologies.
  • Testing an application written in Spring is easy because environment-related code is moved into this framework. In addition, by using JavaBean-style POJOs, it becomes easier to inject test data with dependency injection.
  • Spring's web framework is a well-designed web MVC framework that provides a good alternative to web frameworks such as Structs or other engineering or less popular web frameworks. T he MVC pattern separates different aspects of the application (input logic, business logic, and UI logic) while providing loose coupling between these elements. M odel encapsulates application data, which typically consists of POJO classes. V iew is responsible for rendering model data, and in general it generates HTML output that the client browser can interpret. Controller is responsible for processing user requests and building appropriate models and passing them to the view for rendering.
  • Spring provides encapsulation for some of the most difficult APIs in JavaEE development (JDBC, JavaMail, remote calls, etc.) to make these API applications much less difficult.
  • Lightweight IOC containers are often lightweight, especially when compared to EJB containers. This facilitates the development and deployment of applications on computers with limited memory and CPU resources.
  • Spring provides a consistent transaction management interface that scales down (using a single database, for example) local transactions and global transactions (for example, using JTA).

Dependency Injection (DI)

Spring's most recognized technology is the Dependency Injection (DI) pattern that controls inverse. Control Inverse (IoC) is a common concept that can be expressed in many different ways, and dependency injection is just one concrete example of controlling inverse.

When writing a complex Java application, application classes should be as independent as possible of other Java classes to increase the likelihood that these classes can be reused, and when unit testing is performed, they can be tested independently of other classes. Dependency injection (or sometimes called wiring) helps bind these classes together and keep them independent at the same time.

What exactly is dependency injection? L et's look at the two words separately. H ere the dependency part is transformed into an association between two classes. F or example, class A depends on class B. N ow, let's take a look at the second part, Injection. All this means that Class B is injected into Class A through IoC.

Dependency injections can occur by passing arguments to the constructor, or by using the setter method post-construction. Since dependency injection is a core part of the Spring framework, I'll use good examples in a separate section to explain the concept.

Face-oriented programming (AOP):

A key component of the Spring framework is the facet-oriented Program Design (AOP) framework. T he functionality of a program that spans multiple points is called cross-cutting concerns, which are conceptually independent of the application's business logic. There are a variety of common good examples of aspects, such as logging, declarative transactions, security, and caching, and so on.

The key units that are modular in OOP are classes, while the key units that are modular in AOP are aspects. AOP helps you separate cross-cutting concerns from the objects they affect, but dependency injection helps you separate your application objects from each other.

The AOP module of the Spring framework is mentioned

It provides an aspect-oriented program design implementation that defines things like method interceptors and entry points, so that the code that implements the functionality is completely decoupled. W ith source-level metadata, you can combine behavioral information into your code in a manner similar to the .Net property. I'll discuss more about the concept of Spring AOP in a separate section.