Spring learning notes

Posted by predator12341 on Mon, 07 Mar 2022 20:31:57 +0100

This article is a personal note based on the video of crazy God on bilibili



Spring framework is an open source J2EE application framework. It is a lightweight container for managing the life cycle of bean s. It solves many common problems encountered by developers in J2EE development.

In short, the purpose of Spring is to help solve the complexity of enterprise application development.

Developer: Rod Johnson received not only a computer degree but also a music degree from the University of Sydney. What's more surprising is that he also received a doctorate in musicology before returning to the field of software development.

Concept: making the existing technology easier to use is a hodgepodge, integrating the existing technology framework

1.2 design philosophy


  1. When you come into contact with a framework, you should not only know how the framework is used, but also understand the design principles of the framework. The following are the design principles of the Spring framework:

  2. Options are available at each level. Spring allows you to postpone your choice as much as possible. For example, you can switch the provider of data storage through the configuration file without changing the code. This rule is also well applied to integration with third-party API s.

  3. Adapt to different perspectives. Spring is flexible, and it doesn't force you to decide what to choose. It supports a wide range of application requirements from different perspectives.

  4. Maintain strong backward compatibility. The development of spring has been carefully managed, so that there are almost no separated changes between versions. Spring supports a carefully selected range of JDK versions and third-party libraries to facilitate the maintenance of spring dependent applications and libraries.

  5. Care about API design. The Spring team has invested a lot of thought and time in making intuitive APIs that can be used in multiple versions and can be used for many years.

  6. Set high standards for code quality. The Spring framework focuses on meaningful, up-to-date and accurate JavaDoc. It is one of the few projects that can declare a clean code structure without circular dependencies between packages.

<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->

1.2 advantages

  • Spring is an open source free framework (container)

  • Spring is a lightweight, non intrusive framework

  • Inversion of control (IOC) aspect oriented programming (AOP)

  • Support transaction processing and framework integration

Spring is a lightweight framework for inversion of control (IOC) and aspect oriented (AOP) programming


1.3 composition

  • Spring Boot

    • A rapidly developed scaffold

    • Based on SpringBoot, you can quickly develop a single microservice

    • Contract greater than configuration

  • Spring Cloud

    • Spring cloud is implemented based on SpringBoot


The premise of learning SpringBoot is to master Spring and Spring MVC

Disadvantages: after too long development, it runs counter to the original concept, and the configuration is cumbersome, which is jokingly called "configuration hell"


2.IOC theoretical derivation

1.UserDao interface

2.UserDaoImpl implementation class

3.UserService business interface

4.UserServiceImpl business implementation class


The biggest change is that the programmer in the original development should constantly change the code according to the user's needs (obviously, it takes a lot of manpower and material resources) into a program that can be changed passively according to the user's different needs

public class UserServiceImpl implements UserService {
    private UserDao userDao;
    //Dynamic value injection using Set
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;

In essence, it solves the inconvenience of creating artificial management objects in the business, greatly reduces the system coupling, and can focus more on the realization of the business

Topics: Java Spring Back-end SSM