When you press Run, Spring needs to read the configuration file, save the configuration file information, and instantiate the objects it manages based on that information. Spring takes care of this complex initialization management, so let’s deploy its source code and see what happens when it’s born.

First, you need to create a corresponding container, we ClassPathXmlApplicationContext, for example, after entering a constructor down debugging:

As you can see, it carries the configuration file and calls a Refresh () method implemented by its parent class. From this we can conclude that Refresh () is the core method for spring startup, which performs many of the steps we discussed above. So let’s go straight to his second line of code:

A BeanFactory object is returned, so we assume there will be the creation of the Bean factory, and then we can get the object from the factory.

So that's why we have to pay attention to naming conventions when we're writing code, so that people can look at it later, and that's reflected here, right

Click on this method, inside the method call again. When we follow up, we find that the method is abstract, so see if any of its subclasses have concrete implementations:

It's pretty obvious up here that it's a hook method. Those unfamiliar with the template method pattern can refer to my design Patterns section.

Entering the subclass’s implementation, you can see that createBeanFactory () creates an object, but its internal value is empty (it hasn’t been assigned yet).

This object is an object held by the current class:

Moving on, there’s another hook method. Let’s click on its subclass implementation:

After a long follow-up, we found our destination:

When you look at abstract methods, your first thought should be hooks. Step back and see if there are any subclass implementations:

Sure enough, in subclasses of XML implementations, we finally see hope:

Spring eventually reads the configuration file into InputSource, a class that comes with the JDK to parse XML. Yes, after all this time, Spring has finally decided to parse this configuration file.

At this point, Spring has read the XML into Document, completing the first step of loading into memory.

As the arrow method follows, we can also guess its next step: parsing the Document object further to get every tag in the XML ready for instantiation.

You can see that Spring breaks down the parsing into two categories, default tags and custom tags.

Due to limited space, the detailed parsing process of labels will be covered separately in the next article.

As you can see from this article,Spring itself is more tightly packaged, so it can be complicated to analyze, but this is the way every programmer must go, come on!