In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "analyzing the past life and this life of the Spring framework". In the daily operation, I believe that many people have doubts in analyzing the past life and this life of the Spring framework. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "analyzing the past life and this life of the Spring framework". Next, please follow the editor to study!
Learning objectives of this article
1. Master the basic structure of Spring and the dependence of each sub-module.
2. Understand the development history of Spirng and enlighten your thinking.
3. Form an overall understanding of Spring to pave the way for further study.
4. Understand the rules of Spring version upgrade and apply it to your own system upgrade version naming.
The past Life and present Life of Spring
I believe that after 70 or 80 years of not using a framework to develop Web projects, today's programmers' development projects are so easy that they basically only need to care about how the business is implemented, and general technical problems only need to integrate the framework.
Back in 2007, an open source framework based on the Java language was officially released with a very dynamic and beautiful name, Spring.
It is an open source lightweight Java SE (Java Standard Edition) / Java EE (Java Enterprise Edition) development application framework designed to simplify enterprise application development.
An application is made up of a set of objects that cooperate with each other. In traditional application development, a complete application is composed of a set of objects that cooperate with each other.
Therefore, in addition to developing business logic, the most important thing to develop an application is to focus on how to make these objects cooperate to complete the required functions, and to have low coupling and high aggregation. Business logic development is inevitable, so if there is a framework to help us create objects and manage the dependencies between these objects.
Someone may have said, for example, "Abstract Factory, Factory method pattern" can also help us create objects, "Generator pattern" can help us deal with the dependencies between objects, can not also accomplish these functions?
However, these require us to create other factory classes and generator classes, and we have to manage these classes outside, which increases our burden. If there is a way to create objects and manage dependencies between objects through configuration, we do not need to create and manage dependencies between objects through factories and generators, so do we reduce a lot of work and speed up development? It can save a lot of time to do other things.
When the Spring framework first came out, it was mainly to complete this function.
The Spring framework not only helps us manage objects and their dependencies, but also provides aspect-oriented capabilities such as general logging, performance statistics, security control, exception handling, etc., and also helps me manage the most troublesome database transactions. It provides a set of simple JDBC access implementation, provides integration with third-party data access frameworks (such as Hibernate, JPA), and integrates with various Java EE technologies (such as Java Mail, task scheduling, etc.) Provide a set of own Web layer framework Spring MVC, but also can be very easy to integrate with third-party Web framework.
From here, we can think of Spring as a super glue platform, which not only provides its own functions, but also provides the ability to glue other technologies and frameworks, so that we can choose more freely what technologies to use for development.
And both JAVA SE (Cramp S architecture) applications and JAVA EE (Bhand S architecture) applications can be developed using this platform. Today's Spring is no longer a framework, but has already become a kind of ecology.
The convenient development of SpringBoot realizes zero configuration and SpringCloud family bucket, which provides a very convenient solution. Next, let's take a closer look at what Spring can bring to us.
It all started with Bean.
When it comes to the concept of Bean, we have to start from the origin of Java.
As early as 1996, Java was just a new, fledgling programming language. People pay attention to her only because Java's Applet can be used to develop Web applications as browser components.
But developers soon found that this emerging language could do more.
Unlike all previous languages, Java made it possible to build complex systems by modularization. (although the software industry developed by leaps and bounds in business at that time, it was developed with the traditional idea of process-oriented development, and the efficiency of software development has been hesitant.
With the increasing complexity of the business, development becomes more and more difficult.
In fact, it was also a period of rapid development of OOP thought, which was proposed in the late 1980s and matured in the 1990s, and most programming languages are already object-oriented today.
In December of the same year, Sun released the JavaBean 1.00 Murray A specification, which was unknown at the time but was later well known. The early JavaBean specification was aimed at Java, which defined the software component model.
This specification defines a set of coding strategies so that simple Java objects can not only be reused, but also can easily build more complex applications.
Although JavaBean was originally designed to reuse application components, they were mainly used to build form controls at the time, which was mainstream in the PC era.
But compared with the heyday of Delphi, VB and Cruise, it still looks too easy to meet any "actual" job needs.
Complex applications usually need the support of transaction, security, distributed and other services, but JavaBean does not provide them directly.
So in March 1998, Sun released the EJB 1.0 specification, which extends the design concept of Java components to the server side and provides many necessary enterprise services, but it is no longer as simple as the early JavaBean.
In fact, apart from the name EJB Bean, the others have little to do with JavaBean.
Although many real-world systems are built on EJB, EJB never achieves its original vision of simplifying development.
EJB's declarative programming model does simplify development at many infrastructure levels, such as transactions and security
On the other hand, EJB becomes extremely complex in terms of deployment descriptors and supporting code implementation. Over time, many developers have become disillusioned with EJB and began to look for a more concise approach.
Now the concept of Java component development is back on track. With the continuous emergence of new programming technologies AOP and DI, they provide JavaBean with the powerful features that EJB could have before. These technologies provide POJO with a declarative programming model similar to EJB without introducing any of the complexity of EJB.
When simple JavaBean is good enough, people are reluctant to write clunky EJB components.
Objectively speaking, the development of EJB has even promoted the POJO-based programming model. With the introduction of new ideas, the latest EJB specification is unprecedentedly simplified compared to the previous specification, but for many developers, it all comes too late.
By the time the EJB 3 specification was released, other POJO-based development architectures had become the de facto standard, and the Spring framework emerged in this context.
The original intention of Spring design
Spring is designed to solve the complexity of enterprise application development, and she can do a lot of things. But in the final analysis, it is only a few basic ideas that underpin Spring, all of which can be traced back to a fundamental mission: to simplify development.
This is a solemn commitment, but many frameworks claim to be simplified in some ways. On the other hand, Spring is determined to simplify Java development in all aspects.
In this regard, she mainly adopted four key strategies:
1. Lightweight and least intrusive programming based on POJO
2. Through dependency injection and interface-oriented loose coupling
3. Declarative programming based on section and inertia
4. Reduce the template code through sections and templates
It is mainly achieved through three ways: Bean-oriented (BOP), dependency injection DI and aspect-oriented AOP.
The beginning of BOP programming
Spring is Bean-oriented programming (Bean Oriented Programming, BOP), and Bean is the real protagonist in Spring. The role of Bean in Spring is the same as the meaning of Object to OOP. Without Bean in Spring, there is no meaning of Spring.
Spring provides the IOC container to manage dependencies between objects through configuration files or annotations.
Inversion of control (the most common implementation is called dependency injection (Dependency Injection,DI), and another is called dependency search (Dependency Lookup,DL), which is used in C++, Java, PHP, and .NET.
In the earliest Spring, there were dependency injection methods and dependency queries, but because dependency queries were not used frequently, they were soon removed by Spring, so inversion of control is also directly called dependency injection in Spring. Her basic concept is: do not create objects, but describe how to create them.
Do not connect directly to objects and services in the code, but describe which component needs which service in the configuration file.
Containers (IOC containers in the Spring framework) are responsible for linking these together.
In a typical IOC scenario, the container creates all the objects and sets the necessary properties to connect them together to determine when the method is called.
The basic concept of dependency injection
The core org.springframework.beans package of Spring design (the core of the architecture is the org.springframework.core package), which is designed to be used with JavaBean components.
This package is not usually used directly by the user, but is used by the server as the underlying intermediary for most other functions. The next highest-level abstraction is the BeanFactory interface, which is an implementation of the factory design pattern that allows objects to be created and retrieved by name. BeanFactory can also manage relationships between objects.
BeanFactory supports two object models at the lowest level.
1, singleton: provides a global shared instance object with a specific name, which can be retrieved when querying. Singleton is the default and most commonly used object model.
2, prototype: make sure that a separate instance object is created for each retrieval. Use the prototype pattern when each user needs his or her own object.
The concept of a Bean factory is the basis for Spring as an IOC container.
IOC shifts responsibility for handling things from the application code to the framework.
AOP programming concept
Aspect-oriented programming, or AOP, is a programming idea that allows programmers to modularize the behavior of crosscutting concerns or typical boundaries of responsibility, such as logging and transaction management.
The core construct of AOP is aspects (aspects), which encapsulate behaviors that affect multiple classes into reusable modules.
AOP and IOC are complementary technologies that use modularization to solve complex problems in enterprise application development.
In a typical object-oriented development approach, logging statements may have to be placed in all methods and Java classes to achieve logging functionality.
In the AOP approach, log services can, in turn, be modularized and applied declaratively to components that require logging.
The advantage, of course, is that the Java class does not need to know about the existence of the logging service, nor does it need to consider the relevant code. Therefore, the application code written in Spring AOP is loosely coupled.
The functionality of AOP is fully integrated into the context of Spring transaction management, logging, and various other features.
The common scenarios of AOP programming are: Authentication (authority authentication), Auto Caching (automatic cache processing), Error Handling (unified error handling), Debugging (debug information output), Logging (logging), Transactions (transaction processing) and so on.
Spring5 system architecture
Spring has a total of about 20 modules and is made up of more than 1300 different files. These components are integrated in the core container (Core Container), AOP (Aspect Oriented Programming) and device support (Instrmentation), data access and integration (Data Access/Integeration), Web, message transmission (Messaging), Test,6 module set.
The following is the module structure diagram of Spring 5:
Each collection of modules or modules that make up the Spring framework can exist alone or can be implemented jointly by one or more modules. The composition and functions of each module are as follows:
Core container
It consists of four modules: spring-beans, spring-core, spring-context and spring-expression (Spring Expression Language, SpEL).
Spring-core and spring-beans modules are the core modules of Spring framework, including control inversion (Inversion of Control, IOC) and dependency injection (Dependency Injection, DI).
The BeanFactory interface is the core interface in the Spring framework, and it is the concrete implementation of the factory pattern. BeanFactory uses control inversion to separate the application's configuration and dependency specifications from the actual application code. However, the BeanFactory container does not instantiate the Bean automatically after instantiation, and the BeanFactory container assembles the instantiation and dependency of the Bean only when the Bean is used.
The spring-context module is built on top of the core module. He extends BeanFactory and adds functions such as Bean lifecycle control, framework event architecture and resource loading transparency for her.
In addition, the module also provides a lot of enterprise-level support, such as mail access, remote access, task scheduling and other ApplicationContext is the core interface of the module, and its superclass is BeanFactory.
Unlike BeanFactory, after instantiation, the ApplicationContext container automatically instantiates and assembles all single-instance Bean, making it ready for use.
The spring-context-support module is an extension to the Spring IOC container, as well as the IOC child container.
The spring-context-indexer module is the class management component of Spring and Classpath scanning.
Spring-expression module is the extension module of Unified expression language (EL), which can not only query and manage running objects, but also call object methods, operation arrays, collections and so on.
Its syntax is similar to that of traditional EL, but provides additional functions, the best of which are function calls and template functions for simple strings. The features of this language are based on the requirements of Spring products, and it can easily interact with Spring IOC.
AOP and device support
It consists of three modules: spring-aop, spring-aspects and spring-instrument.
Spring-aop is another core module of Spring and the main implementation module of AOP. As one of the programming ideas that have the greatest influence on programmers after OOP, AOP has greatly expanded people's thinking on programming.
In Spring, he is based on the dynamic proxy technology of JVM, and then designs a series of AOP crosscutting implementations, such as pre-notification, return notification, exception notification and so on. At the same time, the Pointcut interface matches the pointcut, which can use the existing pointcut to design the crosscutting, or expand the relevant methods to cut in according to the needs.
The spring-aspects module is integrated from the AspectJ framework, mainly to provide a variety of AOP implementation methods for Spring AOP.
The spring-instrument module is designed based on the "java.lang.instrument" in JAVA SE, which should be regarded as a supporting module of AOP. The main function is to generate a proxy class when JVM is enabled. Programmers modify the bytes of the class at run time through the proxy class, thus changing the function of a class and realizing the function of AOP. In the category, I classified him under the AOP module, and there is also some ambiguity about this place in the official Spring documentation. This is a purely personal point of view.
Data access and integration
It consists of five modules: spring-jdbc, spring-tx, spring-orm, spring-jms and spring-oxm.
The spring-jdbc module is the main implementation module of the JDBC abstract framework provided by Spring, which is used to simplify the Spring JDBC operation.
It mainly provides JDBC template mode, relational database object mode, SimpleJdbc mode and transaction management to simplify JDBC programming. The main implementation classes are JdbcTemplate, SimpleJdbcTemplate and NamedParameterJdbcTemplate.
Spring-tx module is the implementation module of Spring JDBC transaction control. Using Spring framework, it encapsulates transactions well, and can be flexibly configured at any layer through its AOP configuration; but in many requirements and applications, directly using JDBC transaction control still has its advantages. In fact, transactions are based on business logic; a complete business should correspond to a method in the business layer
If the business operation fails, the entire transaction is rolled back; therefore, transaction control should definitely be placed in the business layer; however, the design of the persistence layer should follow a very important principle: to ensure the atomicity of the operation, that is, every method in the persistence layer should be indivisible.
Therefore, when using Spring JDBC transaction control, you should pay attention to its particularity.
Web component
It consists of four modules: spring-web, spring-webmvc, spring-websocket and spring-webflux.
The spring-web module provides the most basic Web support for Spring, which is mainly based on the core container, initializes the IOC container through Servlet or Listeners, and also includes some Web-related support.
Spring-webmvc module is well known as a Web-Servlet module, which implements the Web application of Spring MVC (model-view-Controller).
The spring-websocket module is mainly a protocol for full-duplex communication with the front end of Web.
Spring-webflux is a new non-blocking functional Reactive Web framework that can be used to build asynchronous, non-blocking, event-driven services with good scalability.
Communication message
The spring-messaging module is a new module added from Spring4. Its main responsibility is to integrate some basic messaging applications for the Spring framework.
Integration testing
That is, the spring-test module, which mainly provides support for testing, after all, it is very important for any enterprise to be able to perform some integration tests or other tests without publishing to your application server or connecting to other enterprise facilities.
Integrated compatibility
That is, spring-framework-bom module, Bill of Materials. Solve the problem that different modules of Spring depend on different versions.
Dependencies between modules
I made a systematic summary of each module of Spring5, describing the dependency between modules, hoping to be helpful to my friends.
In the next series of "in-depth Spring5 source code series", we will take a closer look at the core module functions of Spring.
The basic learning order is: start with spring-core, followed by spring-beans and spring-aop, followed by spring-context, followed by spring-tx and spring-orm, and finally spring-web and other parts.
Naming rules for Spring versions
The format of the version number is X.Y.Z (also known as Major.Minor.Patch):
X represents the major version number, and X needs to be incremented when the compatibility of API changes.
Y represents the minor version number, and Y needs to be incremented when the function is added (without affecting the compatibility of API).
Z represents the revision number, and Z needs to be incremented when it is fixed by Bug (without affecting API compatibility).
The detailed rules are as follows:
X, Y, Z must be non-negative integers, must not contain leading zeros, and must be incremented by numerical values, such as 1.9.0-> 1.10.0-> 1.11.0.
The version number of 0.Y.Z indicates that the software is in the initial development stage, which means that API may be unstable; 1.0.0 indicates that the version already has a stable API.
When the compatibility of API changes, X must be incremented and Y and Z are set to 0 at the same time
When adding new features (without affecting API compatibility) or when API is marked as Deprecated, Y must be incremented and Z must be set to 0; when bug fix is performed, Z must be incremented.
The advance version number (Pre-release) means that the version is unstable and there may be compatibility problems. Its format is: X.Y.Z. [a Murc] [positive integer], such as 1.0.0.a1, 1.0.0.b99, 1.0.0.c1000.
The development version number is often used for CI-CD in the format of X.Y.Z.dev [positive integer], such as 1.0.1.dev4.
The sorting rule of the version number is to compare the values of the major version number, the minor version number, and the revision number, such as 1.0.0 < 1.0.1 < 1.1.1 < 2.0.0.
For the advance version number and the development version number, there are: 1.0.0.a100 < 1.0.0, 2.1.0.dev3 < 2.1.0; when there are letters, they are compared in the order of ASCII, such as 1.0.0.a1 < 1.0.0.b1.
Common version modifiers
Snapshot: versions represent unstable versions that are still under development
Alpha: build
Beta: beta version
Demo: demo version
Enhance: enhanced version
Free: free version
Full Version: full version, that is, official version
LTS: long-term maintenance version
Release: distribution
RC: will be released as an official version soon
Standard: standard Edition
Ultimate: flagship edition
Upgrade: upgraded version
Spring version modifier
Release: stable version
GA: a widely available stable version (General Availability)
M: milestone version (Milestone) has some new features or landmark versions
RC: will be released as an official version soon (Release Candidate)
At this point, the study of "analyzing the past life and this life of the Spring framework" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.