spring source of IOC container resource locator process

bedding

        Usually when we use spring practice project, for certain implementations logic underlying the majority they have been ignored before, but understanding the underlying implementation but often we solve a problem in practice, the most favorable aid. Here is what I read the source code of conduct and organize some learning notes.


Ready to work

        In a development environment to build their own spring source environment, I am using IDEA development tools to build a search online a lot of steps, the following spring source attach a build environment in IDEA link:

        blog.csdn.net/u011976388/…


text

       After build a good environment, before reading the source code, I feel the need to understand the implementation and inheritance structure next spring container classes, below is the most complete of a picture I found (and perhaps the best-looking), if necessary can collection together.


     Today, we are FileSystemXmlApplicationContext container classes, for example, analyzing the call initialization process container.

     Start initialization spring IoC container is simply called by the refresh () method to start, this method marks the official launch of the IoC container. Specifically, the start there are three main steps (you can write down):

  • Resource positioning of BeanDefinition
  • BeanDefinition load
  • Registration BeanDefinition

      Need to be reminded, spring to separate these three processes, and the use of different modules to complete, this design approach is that it gives users more flexibility in tailoring these three processes and develop, define the most suitable own IoC initialization process container.

       Today, we first analyze the first process is the Resource positioning process, follow-up article continues to record the remaining two loading process, we can see three processes are initialized and associated BeanDefinition this thing, first is that what is BeanDefinition

       BeanDefinition refers to abstraction we define the Bean, the main function is to allow container data types, for IoC container is, BeanDefinition is dependent on the relationship between the abstract data object dependency inversion mode management, as well as containers for reversing function the core data structure, dependent reverse function revolves around dealing with this BeanDefinition to complete.

        The following is the call flow diagram Resource Locator I sorted out (selection flowchart is because the complicated inheritance structures, most of polymorphic method calls the process to achieve such positioning method may be more trouble, so use the flowchart)

     

              

       According to this flow chart, it has been set up in front of a good spring source environment to see concrete action, but I figure already in the remarks out of the general content of each call link.

       We can see FileSystemXmlApplicationContext inherited DefaultResourceLoader and rewrote getResourceByPath, then get in AbstractBeanDefinitionReader FileSystemResource instance of an object class. This object represents our definition of good information resource configuration, through this object, you can perform the IO operation completes the positioning of BeanDefinition     

       If other containers implementation class, will be generated corresponding to the type of Resource, such ClassPathResource, ServletContextResource the like, the relationship between Resource inheritance of FIG.

       


to sum up

       If we take as a bucket IOC container, it can be said BeanFactory is defined as the basic functions of a bucket (e.g. at least filled with water and the like), interface definitions provided in the spring and substantially IoC container based on the realization, by spring BeanDefinition defined to manage the various objects in Spring applications, and their dependencies between objects, BeanDefinition our definition Bean abstraction, these BeanDefinition like containers filled with water, with these basic data, the vessel will be able to play effect.

      We realized from the analysis of the previous principle, understand the solutions Resource locate the problem, namely to locate problems FileSystem Resource way, based on BeanDefinition positioning is completed, it can be loaded BeanDefinition object returned by Resource , and after positioning is completed, the created operating conditions I O / BeanDefinition for the following loading. We need the equivalent of a bucket to hold water, the location of water sources have been identified.


Here is my own to open a public number, mainly to record their study notes, articles will be updated later updated in sync number corresponding to the public, interested in understanding can focus the next.

 

                                            


Guess you like

Origin juejin.im/post/5cf1e570e51d45775c73dc84