A detailed explanation of the Spring framework


insert image description here

basic concept

  The Spring framework was created due to the complexity of software development . Spring uses basic JavaBeans to do things that were previously only possible with EJBs. However, Spring's uses are not limited to server-side development. Most Java applications can benefit from Spring in terms of simplicity, testability, and loose coupling.One of the biggest goals of Spring is to make Java EE development easier. At the same time, the reason why Spring is different from single-layer frameworks such as Struts and Hibernate is that Spring is committed to providing a unified and efficient way to construct the entire application, and can combine the single-layer framework with the best combination to build a coherent system. It can be said that Spring is a framework that provides a more complete development environment and can provide enterprise-level services for POJO (Plain Ordinary Java Object) objects.

Formation of Spring

  The formation of Spring originally came from an influential book "Expert One-on-One J2EE Design and Development" by Rod Jahnson, in which some of the core ideas of Spring first appeared. The book was published in 2002. Another book, "Expert One-on-One J2EE Development without EJB", further elaborates some design ideas and specific practices for developing JAVA EE enterprise-level applications without using EJB. When you have time, you can read it in detail. Of course, the Spring framework provides a set of basic services for Java applications. The purpose is to simplify the development of enterprise applications. It makes developers only need to care about business needs.

main module

It mainly includes the following seven modules:
  (1) Spring Context : provides framework-style Bean access, as well as enterprise-level functions (JNDI, scheduled tasks, etc.);
  (2) Spring Core : core class library, all functions depend on this class Libraries that provide IOC and DI services;
  (3) Spring AOP : AOP services (including classes used when using AOP features);
  (4) Spring Web : Provides basic web-oriented comprehensive features and provides access to common frameworks For example, with the support of Struts2, Spring can manage these frameworks, inject Spring resources into the frameworks, and insert interceptors before and after these frameworks;
  (5) Spring MVC : Provides Model-View-Controller for Web applications, that is, MVC implementation .
  (6) Spring DAO : the abstract encapsulation of JDBC, which simplifies the processing of data access exceptions and can manage JDBC transactions in a unified manner;
  (7) Spring ORM : supports the existing ORM framework;
here is a detailed description of the Spring MVC module Introduction:
  MVC 模式(Model–view–controller)It is a software architecture pattern in software engineering. It divides the software system into three basic parts: Model, View and Controller. The idea is to divide the whole project into coupling of multiple parts; and it is mainly divided into: M model block, which is an abstract parent class; V view block, which prints out user interaction information; C control block: used to implement various operations on data .

Three-tier architecture

At the same time, the standard three-tier architecture can also be understood as follows:

  (1) Data access layer: It is mainly the operation layer of raw data (database or text file, etc.), rather than raw data, that is to say, it is the operation of data, not the database, specifically the business The logic layer or presentation layer provides data services.

  (2) Business logic layer: It is mainly for the operation of specific problems. It can also be understood as the operation of the data layer and the processing of data business logic. If the data layer is a building block, then the logic layer is the construction of these building blocks. Specifically, it is mainly responsible for the operation of the data layer. That is to say, some data layer operations are combined.

  (3) Presentation layer: It mainly represents the WEB mode. If the logic layer is quite powerful and perfect, no matter how the presentation layer is defined and changed, the logic layer can provide services perfectly. It mainly accepts the user's request and returns the data to provide the client with access to the application.

Advantages of Spring

Spring also has the following advantages:
  (1) Convenient decoupling and simplified development: Spring is a big factory, which can hand over all object creation and dependency relationship maintenance to Spring management.
  (2) AOP programming support: Spring provides aspect-oriented programming, which can easily implement functions such as permission interception and operation monitoring of programs.
  (3) Support for declarative transactions: The management of transactions can be completed only through configuration without manual programming.
  (4) Convenient program testing: Spring supports Junit4, and Spring programs can be easily tested through annotations.
  (5) It is convenient to integrate various excellent frameworks: Spring does not exclude various excellent open source frameworks, and provides direct support for various excellent frameworks (such as: Struts, Hibernate, MyBatis, etc.).
(6) Reduce the difficulty of using Java EE APIs: Spring provides encapsulation for some APIs (JDBC, JavaMail, remote calls, etc.) that are very difficult to use in Java EE development, which greatly reduces the application difficulty of these APIs.

Design patterns are used in the Spring framework:

  (1) Factory mode: Spring uses the factory mode to create objects through BeanFactory and ApplicationContext. It is an interface that provides access classes with an interface to create a set of related or interdependent objects, and the access classes do not need to specify the specific class of the desired product. Obtain the schema structure of different grades of products of the same family.
  (2) Singleton mode: refers to a mode in which a class has only one instance, and the class can create this instance by itself. Bean defaults to the singleton mode.
  (3) Strategy mode: For example, the implementation class of Resource implements different resource acquisition strategies for different resource files.
  (4) Proxy mode: It is divided into static proxy mode (the bytecode file of the proxy class already exists before the program runs) and dynamic proxy mode (the proxy mode created by the proxy class when the program is running). Spring's AOP function uses JDK (5) Template method: You can put the same part of the code in the parent class, and put different codes
  in different subclasses to solve the problem of code duplication. For example RestTemplate, JmsTemplate, JpaTemplate
  (6) Adapter mode: Spring AOP enhancement or advice (Advice) uses the adapter mode, Spring MVC also uses the adapter mode to adapt Controller
  (7) Observer mode: Spring event-driven model is to observe A classic application of the moderator mode.
  (8) Bridge mode: Different data sources can be dynamically switched according to customer needs. For example, our project needs to connect to multiple databases, and customers will access different databases according to their needs in each visit.
insert image description here

Guess you like

Origin blog.csdn.net/S_yyuan/article/details/123161507