Spring is an open source full-stack application framework and inversion of control container implementation for the Java platform. Some of the core features of the framework can theoretically be used in any Java application, but Spring also provides extensive support for Web applications built on the Java Enterprise Edition platform. Although Spring does not directly implement any programming model, it has become so popular in the Java community that it has almost completely replaced the enterprise JavaBeans (EJB) model.
I. Version history
The first version was developed by Rod Johnson and published in The Expert One-To-one J2EE Design and Development in October 2002. The Spring Framework was first released under the Apache 2.0 license in June 2003. Milestone version 1.0 was released in March 2004, and new milestone versions were released in September 2004 and March 2005. In 2006, the Spring Framework won the Jolt Productivity Award and the JAX Innovation Award.
Spring 2.0 was released in October 2006, Spring 2.5 in November 2007, Spring 3.0 in December 2009, Spring 3.1 in 2011, Spring 3.2.5 in November 2013, and version 4.0 in December 2013. Notably, Spring 4.0 has added support for Java SE 8, Groovy 2, some aspects of Java EE 7, and WebSocket.
In September 2017, version 5.0 of the Spring Framework was released, which introduces Spring WebFlux, a high-performance, responsive, asynchronous Web Framework. Spring 5.0’s focus on functional programming, reactive programming support is a big step forward.
Ii. Core functional modules
- Powerful Javabeans-based configuration management using Inversion of Control (IoC) principles makes application construction easier and faster.
- A core Bean factory that can be used in runtime environments such as Java EE.
- A generalized abstraction layer for database transactions allows Declarative transaction managers to simplify transaction partitioning and make it irrelevant to the underlying layer.
- The built-in generalization strategy for JTA and a single JDBC data source does not require a Java EE environment for Spring’s transaction support, as opposed to normal JTA or EJB CMT.
- The JDBC abstraction layer provides targeted exception levels (no longer extracting raw code from SQL exceptions), simplifying error handling and greatly reducing programmer coding. When using JDBC again, you don’t need to write another ‘finally’ module. And jDBC-oriented exceptions are consistent with Spring common Data Access Object exception levels.
- Integrate with Hibernate, JDO, MyBatis and SQL Maps in the form of resource containers, DAO implementations and transaction strategies. The inversion of control mechanism solves many typical Hibernate integration problems comprehensively. All of these comply with the Spring common Transaction and Common Data Access Object exception level specifications.
- Flexible MVC Web application framework based on core Spring features. Developers will have a high degree of control over the framework through the policy interface, so the framework will be adaptable to multiple presentation (View) technologies, such as JSP, FreeMarker, Velocity, Thymeleaf, etc. It’s worth noting that the Spring middle tier can easily be combined with any WEB layer based on an MVC framework, such as Struts, WebWork, or Tapestry.
- An AOP framework that provides services such as transaction management.
- When designing an application Model, the MVC pattern (such as Struts) often makes it difficult to provide a clean framework. Spring has the ability to make this part of the job easier. Developers can use Spring’s JDBC abstraction layer to redesign complex frameworks.
Start with beans
As early as 1996, Java applets could be used to develop Web applications as browser components. But developers soon found that the emerging language could do more. In December of that year, Sun released the little-known Javabeans 1.00-A specification.
Complex applications typically require transaction, security, and distribution services, but Javabeans don’t provide them directly. So in March 1998, Sun released the EJB1.0 specification, which extended the design philosophy of Java components to the server side and provided many necessary enterprise-level services, but it was no longer as simple as the early javabeans. In fact, aside from the name EJB Beans, they have little to do with Javabeans.
Despite the fact that many systems are built on EJB, EJB has never achieved what it was originally intended to do: simplify development. EJB’s declarative programming model does simplify many infrastructure aspects of development, such as transactions and security; On the other hand, EJB has become extremely complex in terms of deployment descriptors and supporting code implementation. Over time, many developers have become disillusioned with EJBs and are looking for a cleaner approach.
To be fair, the evolution of EJBs has even promoted a POJO-based programming model. By the time the EJB 3 specification was published, other POJO-based development architectures had become de facto standards, and the Spring framework emerged in this context.
What can Spring bring to us
4.1 Spring’s four basic strategies for simplifying development
- Pojo-based lightweight and minimally invasive programming
- Loose coupling through dependency injection and interface oriented
- Declarative programming based on section and inertia
- Reduce boilerplate code with cuts and templates
Spring is implemented in three main ways: Bean-oriented (BOP), dependency injection (DI), and aspect oriented (AOP).
The relationship between AOP, IOC and DI
4.2 BOP programming
Spring is bean-oriented Programming (BOP), and beans are the real heroes in Spring. Beans are what Objects are to OOP in Spring. Without beans there is no reason for Spring to exist. Spring provides the IOC container to manage dependencies between objects through configuration files or annotations.
Inversion of control (most commonly implemented as Dependency Injection (DI), and Dependency Lookup (DL) are available in C++, Java, PHP, and Java. NET. In the early Spring, dependency injection methods and dependent queries were included, but because of the low frequency of dependent queries, they were removed by Spring soon, so inversion of control is also directly called dependency injection. Objects and services are not directly connected in the code, but which components require which services are described in the configuration file. The container (IOC container in the Spring framework) is responsible for tying these together.
In a typical IOC scenario, the container creates all the objects and sets the necessary properties to wire them together, determining when methods are invoked.
4.3 Dependency Injection
The core of the Spring design org. Springframework. Beans package (core architecture is org. Springframework. Core package), its design goal is to use with JavaBean component. This package is typically not used directly by the user, but is used by the server as an underlying intermediary for most other functions. The next highest level of abstraction is the BeanFactory interface, which is an implementation of the factory design pattern that allows objects to be created and retrieved by name. The BeanFactory can also manage relationships between objects.
At its lowest level, BeanFactory supports two object models:
-
Singleton: Provides a globally shared instance object with a specific name that can be retrieved at query time. Singleton is the default and most commonly used object model.
-
Prototype: Ensure that a separate instance object is created for each retrieval. The prototype pattern is used when each user needs his or her own object.
The Bean factory concept is the foundation of Spring as an IOC container. IOC shifts responsibility for handling things from application code to the framework.
4.4 AOP programming
Section-oriented programming, or AOP, is a programming idea that allows programmers to modularize crosscutting concerns or behaviors that crosscut typical lines of responsibility, such as logging and transaction management. AOP’s core construct is aspects (facets), which encapsulate behaviors that affect multiple classes into reusable modules.
AOP and IOC are complementary technologies that use a modular approach to solve complex problems in enterprise application development. In a typical object-oriented development approach, logging might be implemented by placing logging statements in all methods and Java classes. In the AOP approach, you can, in turn, modularize logging services and declaratively apply them to components that require logging. The advantage, of course, is that Java classes do not need to know about the existence of the logging service, nor do they need to worry about the associated code. Therefore, application code written with SpringAOP is loosely coupled.
AOP’s functionality is fully integrated into the context of Spring transaction management, logging, and various other features.
Common scenarios for AOP programming are: Authentication, Auto Caching, Error Handling, Debugging, Logging, and Transactions.
5. System architecture of Spring5
In total, Spring has about 20 modules, made up of more than 1,300 different files. These components are integrated in Core Container, AOP (Aspect Oriented Programming), and Device support, and Data access and integration, respectively Access/Integeration), Web, Messaging, Test, 6 modules set. Here is the module structure diagram of Spring 5: