Preface: Because of the school’s content is too miscellaneous and not fine, I learned all kinds of languages before, but only to cope with the final exam and teaching. In the previous two semesters, we learned JavaWeb and then directly jumped to Springboot. Unexpectedly, we could barely keep up with it and did two or three small projects with Springboot. During this process, it was inevitable to learn some knowledge about other Spring, Mybatis and so on. But it’s all about understanding. So recently prepared to make up for SSM… Then, I also take notes while studying and update my blog synchronously to prevent the loss of information in the future

I. Introduction case

1. Download

The first step to getting started with a technology is, of course, installation

Liverpoolfc.tv: spring. IO /

Can direct access to the download url: repo. Spring. IO/UI/native/r…

The first step:

The second step:

Step 3:

Step 4:

Step 5:

Step 6:

Step 7:

Note: Since I now know how to use Maven for project management, I use Maven to build the Spring project instead of importing the project with the download JAR above

2. Project creation

The first step:

The second step:

Step 3:

Step 4:

Step 5:

Step 6:

Write the test code and click Test

The following exception was reported in the test because the Spring configuration file could not be found at runtime.

Solutions:

Solution: blog.csdn.net/qq_32575047…

Blog.csdn.net/weixin_3990…

Test result:

Second, the IOC

IOC: Inversion of Control, or lOC, is a design principle used in object-oriented programming to reduce coupling between computer code. One of the most common is called Dependency Injection, or DI, and another is called Dependency Lookup. With inversion of control, when an object is created, it is passed a reference to the object on which it depends by an external entity that regulates all objects in the system. In other words, dependencies are injected into objects. (Simple to understand: Inversion of control, handing over to Spring the management of object creation and calls between objects.)

1. Underlying principles of IOC

  • XML parsing
  • The factory pattern
  • reflection

Examples of the underlying principles of IOC:

2. The IOC interface

1. IOC thought is based on IOC container, and the bottom of IOC container is object factory

2. Spring provides two ways to implement IOC containers :(two interfaces)

  • BeanFactory: The basic implementation of the IOC container. It is an internal interface to Spring and is not available for developers to use

    • Objects are not created when the configuration file is loaded. Objects are created when the object is retrieved
  • ApplicationContext: A subinterface of the BeanFactory interface that provides more powerful functionality and is typically used by developers

    • The configuration file object is created when the configuration file is loaded (although this method is time-consuming, we still use this method because we should leave the time-consuming operation to the server, not the application).

3. The ApplicationContext interface has two main implementation classes

public class TestSpring5 { @Test public void testAdd(){ //1. Load the Spring configuration file ApplicationContext context = new ClassPathXmlApplicationContext (" bean1. XML "); User User = context.getBean(" User ", user.class); System.out.println(user); user.add(); }} in the above the test program, to load the Spring configuration file, if use FileSystemXmlApplicationContext classes in the parameter should be used when the position of "Spring configuration files in the drive" namely drive path as a parameter; If using the ClassPathXmlApplicationContext class should use the classpath classpath as parametersCopy the code

The specific implementation is described as follows:

4. BeanFactory interface

As you can see from today’s lesson, Spring’s main technology is Java’s reflection mechanism, so you will need to review it later if you are not clear about reflection. In addition, notes are followed by the video while watching while doing, but in their own hands after the implementation of the situation with some easy to understand their own words, more rough, will continue to update 😃

That’s the end of today’s study notes!