Spring5 overview

I. Overview

  Spring 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 composed of a set of objects that cooperate with each other. In traditional application
development , a complete application consists of a set of objects that cooperate with each other. Therefore, in addition to developing business logic in developing an application, the
most thing is to focus on how to make these objects cooperate to complete the required functions, and to have low coupling and high cohesion. Business logic development is inevitable,
if there is a framework to help us create objects and manage the dependencies between these objects. Some people may have said, for example, "abstract
factory , factory method design pattern" can also help us create objects, "generator pattern" helps us deal with dependencies between objects,
can't they also complete these functions? However, these require us to create other factory classes and generator classes, and we have to manage these classes externally, which
increases our burden. If there is a way to create objects and manage dependencies between objects through configuration, we will not It is necessary to create and manage dependencies between objects through
factories and generators, so that we can reduce a lot of work, speed up development, and save
a lot of time for other things. When the Spring framework first came out, it was mainly to complete this function.
In addition to helping us manage objects and their dependencies, the Spring framework also provides aspect-oriented capabilities such as general logging, performance statistics, security control, and exception
handling . It can also help me manage the most troublesome database transactions. It provides a simple set of JDBC access implementation of ,
providing integration with third-party data access frameworks (such as Hibernate, JPA), integration with various Java EE technologies (such as Java Mail,
Task scheduling, etc.), provides a set of its own web layer framework Spring MVC, and can be easily integrated
with . From here, we can think that Spring is a super glue platform. In addition to providing its own functions, it also provides the ability to glue other technologies and
frameworks , so that we can more freely choose what technology to use for development. And whether it is JAVA SE (C/S
architecture ) applications or JAVA EE (B/S architecture) applications can be developed using this platform. Let's take a deeper look at what
Spring can do for us?

1.1 , everything starts with beans

  In 1996, Java was just a new, fledgling programming language. People pay attention to her simply because you can use
Java Applets to develop Web applications. But these developers soon discovered that the nascent language could do so much more. Different from all the
previous languages, Java made it possible to build complex systems modularly (although the software industry at that time made rapid progress in business,
but at that time the traditional process-oriented development idea was used for development, and the development efficiency of software has been stagnant. .As the complexity of the business continues to
deepen , the development becomes more and more difficult. In fact, it was also a period of rapid development of object-oriented thinking. It was proposed in the late 1980s and
matured in the 1990s. Most programming languages ​​today are oriented towards object, of course this is another story). They come for Applet and stay for
componentization . This is the earliest Java.

  Also in December of that year, Sun released the then little-known but then well-known JavaBeans
1.00 . The early JavaBean specification was for Java, which defined the software component model. This specification prescribes a set of coding strategies so that not only
simple Java objects can be reused, but also more complex applications can be easily built. Although JavaBeans were originally designed for
reusing application components, they were primarily used for building form controls, which was the norm in the PC era. But compared
to Delphi, VB, and C++, which were in their prime at the time, he still seemed too simple to do any "real" work.

  Also in December of that year, Sun released the then little-known but then well-known JavaBeans
1.00 . The early JavaBean specification was for Java, which defined the software component model. This specification prescribes a set of coding strategies so that not only
simple Java objects can be reused, but also more complex applications can be easily built. Although JavaBeans were originally designed for
reusing application components, they were primarily used for building form controls, which was the norm in the PC era. But compared
to Delphi, VB, and C++, which were in their prime at the time, he still seemed too simple to do any "real" work.

  Complex applications usually require the support of services such as things, security, and distribution, which are not directly provided by JavaBeans.
So in March 1998, Sun released the EJB 1.0 specification, which extended the design concept 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, EJB Beans
have nothing to do with JavaBeans, other than their names.

  Despite the fact that many systems are built on top of EJB, EJB has never lived up to its original vision: to simplify development. EJB's
declarative programming model does simplify development at many infrastructure levels, such as transactions and security; on the other hand, EJBs
become incredibly complex in terms of deployment descriptors and companion code implementation. Over time, many developers became disenchanted with EJBs and started looking
for a cleaner approach.

  Now the Java component development philosophy is back on track. New programming techniques, AOP and DI, continue to emerge, providing JavaBeans with powerful capabilities that were previously only
available in EJBs. These techniques provide POJOs with an EJB-like declarative programming model without introducing
any of the EJB complexities. People are reluctant to write bulky EJB components when simple JavaBeans are sufficient.

  Objectively speaking, the development of EJB has even promoted the POJO-based programming model. Introducing new ideas, the latest EJB specification is unprecedentedly simplified compared to the
previous specification, but for many developers, all this 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
.

1.2 , the original intention of Spring design

  Spring is designed to address the complexities of enterprise application development, and it can do a lot. But at the end of the day, there are
only , all of which can be traced back to one fundamental mission: simplifying development. This is
a serious commitment, and in fact many frameworks claim to be simplified in some way.
Spring is mainly achieved through three ways: Bean-oriented, dependency injection and aspect-oriented.

1.3 ,BOP programming

  Spring is Bean Oriented Programming (BOP), and Bean
is . 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's existence. Spring provides an IOC container to manage dependencies between objects through configuration files or annotations.

  Inversion of Control (the most common of which is called Dependency Injection (DI), and another
called Dependency Lookup (DL), is used in C++, Java, PHP, and .NET. In the earliest Spring
, the dependency injection method and dependency query were included, but because the frequency of dependency query was too low, it was soon removed by Spring,
so inversion of control in Spring is also called dependency injection), she The 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. The container (in the Spring
framework, the IOC container) is responsible for tying this together.

  In a typical IOC scenario, the container creates all the objects, sets the necessary properties to wire them together, and determines when methods are
called .

1.3 , the basic concept of dependency injection

  The core org.springframework.beans package designed by Spring (the core of the architecture is the org.springframework.core
package) is designed to work with JavaBeans components. This package is usually not used directly by the user, but is used by the
server as an 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 the relationship between objects.
BeanFactory supports two object models.

  1. Singleton: A model provides a shared instance of an object with a specific name that can be retrieved at query time. Singleton is the
    default and most commonly used object model. Ideal for stateless service objects.
  2. Prototype: The model ensures that a separate object is created for each retrieval. The prototype model works best when each user needs its own
    object . The concept of a bean factory is the foundation of Spring as an IOC container. IOC shifts the responsibility of handling things from the application code to the framework.

1.4 , AOP programming concept

  Aspect-Oriented Programming, or AOP, is a programming philosophy that allows programmers to modularize
behaviors , such as logging and transaction management. The core construct of AOP is an aspect (aspect), which encapsulates behaviors affecting multiple
classes into reusable modules.

  AOP and IOC are complementary technologies that take a modular approach to solving complex problems in enterprise application development. In a
typical object-oriented development style, logging statements might be placed in all methods and Java classes to implement logging. In the AOP
approach, logging services can be modularized in turn and applied declaratively to components that require logging. The advantage, of course,
is that the Java classes don't need to know about the existence of the logging service, nor do they need to think about the associated code. Therefore, application code
written is loosely coupled.
The functionality of AOP is fully integrated into the context of Spring transaction management, logging, and various other features.
Common scenarios of AOP programming are: Authentication authority authentication, Logging log, Transactions Manager transaction,
Lazy Loading lazy loading, Context Process context processing, Error Handler error tracking (exception capture mechanism)
, Cache cache.

The document has reference to other materials, if you have any questions, please contact me and delete it!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325582033&siteId=291194637