[From zero-learning Spring entry to advanced] day1

Start learning Spring6 today

Chapter 1 "Spring Apocalypse"

1.OCP open and close principle

According to the original structural relationship, when each object needs to be called, it is new by itself, so the request to change will affect the whole body.

OCP (Open Close Principle) is open to extension and closed to modification. When the software needs to change, try to implement the change by extending the behavior of the software entity instead of modifying the existing code.

2. DIP Dependency Inversion Principle

 Purpose: Reduce program coupling and improve scalability

3. The design of the current program obviously violates both OCP and DIP

The programming idea of ​​"inversion of control" can be used to solve this problem. Inversion of control: What is IoC (Inversion of Control) inversion?

Inverted are two things:

  • The first thing: I don't use hard-coded methods to create new objects in the program. (I don't care about the new object, the rights to the new object are handed over.)
  • The second thing: I don't use hard-coded methods in the program to maintain the relationship between objects. (I don't care about the right to maintain the relationship between objects, and hand it over.)

Inversion of Control: It is a programming idea. Or called a new design pattern. Due to the relatively new appearance, it has not been included in the scope of GoF23 design patterns.

So Spring comes on:

  • The Spring framework implements the idea of ​​inversion of control IoC
  • The spring framework can help you with new objects.
  • The Spring framework can help you maintain 'objects and relationships between objects.

Spring is a container that implements the idea of ​​IoC.
There are many ways to implement inversion of control, among which the more important one is called dependency injection (Dependency Injection, DI for short). Dependency injection is a concrete implementation of this idea.
Dependency injection DI includes two common ways:

  • The first type: set injection (execute set method to assign value to attribute>
  • The second type: construction method injection (execute the construction method to assign values ​​to the properties)

What does "dependency" mean in dependency injection? What does "injection" mean?

  • Dependency: the relationship between the A object and the B object.
  • Injection: It is a means by which the A object and the B object can have a relationship.
  • Dependency injection: The relationship between object A and object B is maintained by means of injection. And injection includes: set injection and construction injection.

Chapter 2 "Overview of Spring"

1. Introduction to Spring

Introduction from Baidu Encyclopedia:
Spring is an open source framework created by Rod Johnson. It was created to address the complexities of enterprise application development. Any Java application can benefit from Spring in terms of simplicity, testability, and loose coupling. Spring is a lightweight Inversion of Control (IoC) and Aspect Oriented (AOP) container framework. The first appearance of section Spring was to solve the design of EJB wrist swelling and the difficulty of testing. Spring was born to simplify development, so that programmers only need to focus on the implementation of core business, and no longer pay attention to non-business logic code (transaction control, security log, etc.) as much as possible.


2. Eight modules of Spring

Added WebFlux module after Spring5

 3. Spring Features

1. Lightweight

  • a. Spring is lightweight in terms of both size and overhead. The complete Spring framework can be distributed in a JAR file that is just over 1MB in size. And the processing overhead required by Spring is also negligible.
  • b. Spring is non-intrusive: Objects in Spring applications do not depend on Spring specific classes.

2. inversion of control

  • a. Spring promotes loose coupling through a technique called Inversion of Control (1oC). When IoC is applied, other objects that an object depends on will be passed in passively, rather than the object itself creating or finding dependent objects. You can think of loC as the opposite of NDI - instead of the object finding dependencies from the container, the container actively passes the dependencies to it when the object is initialized without waiting for the object's request.

3. Aspect-oriented

  • a. Spring provides rich support for aspect-oriented programming, allowing cohesive development by separating application business logic from system-level services (such as auditing and transaction management). Application objects only do what they are supposed to do - complete business logic - nothing more. They are not responsible for (or even aware of) other system-level concerns, such as logging or transaction support.

4. container

  • a. Spring contains and manages the configuration and lifecycle of application objects, in the sense that it is a container, you can configure how each of your beans is created - based on a configurable prototype (prototype), your bean can Create a separate instance or spawn a new one every time you need it - and how they relate to each other. However, Spring should not be confused with traditional heavyweight EJB containers, which are often bulky, unwieldy and difficult to use.

5. frame

  • a. Spring can configure and combine simple components into complex applications. In Spring, application objects are composed declaratively, typically in an XML file. Spring also provides a lot of basic functions (transaction management, persistence framework integration, etc.), leaving the development of application logic to you.

All of these Spring features enable you to write cleaner, more manageable, and more testable code. They also provide basic support for various modules in Spring.

Finally, Spring6 requires jdk17 as a minimum, and I will start writing programs tomorrow.

Guess you like

Origin blog.csdn.net/m0_48385518/article/details/128530975