[Spring Notes] Spring Introduction & IOC Theory Derivation

Spring purpose: to solve the complexities of enterprise application development

Pros: Spring is a lightweight Inversion of Control (ioc) and Aspect Oriented (AOP) container framework

spring is an open source free framework (container)

spring is a lightweight non-intrusive framework

Support transaction processing, support for framework integration

Scope: Any java application

Modern java development is based on Spring development

SpringBoot: A scaffold for rapid development. A single microservice can be quickly developed based on SpringBoot. Convention is greater than configuration.

SpringCloud: SpringCloud is implemented based on SpringBoot.

Most companies are using SpringBoot for rapid development. The premise of learning SpringBoot is to fully master Spring and SpringMVC

Disadvantages: It has been developed for too long, and the configuration is very cumbersome

IOC theoretical derivation:

 

 

 

 

 

 Requirement: get mysql database

private UserDao userDao=new UserDaoMysqlmpl();

 Requirement: Get the orcle database

private UserDao userDao=new UserDaoMysqlmpl();

 Every time you get different data, you have to create a different implementation class in new, and change the code manually. The program cannot adapt to changes in requirements.

Solution: use set to dynamically implement value injection (revolutionary changes have been sent)

 

 

 In the previous business, the user's needs may affect the original code, and the original code needs to be modified according to the user's needs.

If the amount of code is large, one modification is expensive. Before, programs actively created objects, and the control was in the hands of the programmer. After using set injection, the program no longer has the initiative, but becomes a passive receiving object.

This is the idea of ​​Inversion of Control.

This kind of thinking solves the problem in essence, without the need for programmers to manage the creation of objects. The coupling of the system is greatly reduced, and you can focus more on business implementation.

This is the prototype of the IOC.

The initiative is handed over from the business layer to the user

 

 

IOC Inversion of Control (Inversion of Control) is a design idea, and DI (Dependency Injection) is a way to implement IOC.

In programs without IOC, we use object-oriented programming. The dependencies between objects created and objects are completely hard-coded in the program. The creation of objects is controlled by the program itself. After control is reversed, the creation of objects is transferred to a third party.

Inversion of control is the inversion of the way to obtain dependent objects

IOC is the core content of the Spring framework. It can be configured using XML or annotations. The new version of Spring can also implement IOC with zero configuration.

When the Spring container is initialized, it first reads the configuration file, stores the object in the container according to the configuration file or metadata and organizes the object, and then takes out the required object from the IOC container when the program is used.

When configuring Beans in XML, the definition information and implementation of Beans are separated, and annotations can be used to integrate the two. Bean definition information is directly defined in the implementation class in the form of annotations, thus achieving the purpose of zero configuration.

Inversion of Control is a way of getting a specific object by description (XML or annotation) and by a third party. It is the IOC container that implements the inversion of control in Spring, and its implementation method is Dependency Injection (DI)


Spring official website download

maven imports spring web mvc dependencies:

https://mvnrepository.com/artifact/org.springframework/spring-webmvc/5.3.19

<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.3.19</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.3.19</version>
</dependency>

Guess you like

Origin blog.csdn.net/m0_52043808/article/details/124371514