Spring source code parsing (a) - Spring container Refresh

Refresh (); refresh container, plus lock
1 prepareRefresh (); ready to refresh the container
  1.1 Modified state (refresh time container, closed container, the container active state)
  1.2 initialization properties resources (empty implementation achieved by subclasses)
  1.3 to initialize the environment resources (Environment), and check the necessary parameters
  1.4 defines a set of events of early (earlyApplicationEvents), for recording the event application broadcaster (the ApplicationEventMulticaster) before initializing a push event, after the broadcast call initialization
2 obtainFreshBeanFactory (); Get BeanFactory
  refreshBeanFactory 2.1 ()
    2.1.1 creating the beanFactory
    2.1.2 modify the refresh state refreshed
    2.1.3 serial number provided
  2.2 returns the beanFactory
. 3 prepareBeanFactory (beanFactory); initializing the beanFactory
  3.1 class loader provided
  3.2 SPEL disposed expression parser (SpelExpressionParser)
  3.3 arranged resource editor (ResourceEditorRegistrar)
  3.4 ApplicationContextAwareProcessor Bean increased post-processor for handling the Bean Aware Interface
    EnvironmentAware environmental data comprises, for acquiring information relating to the environment
      EmbeddedValueResolverAware expression parser for processing string expression. For example "$ {spring.redis.port: 6379}"
      The ResourceLoaderAware resource loader for reading resource data
      ApplicationEventPublisherAware application event pusher for push event (the ApplicationEvent)
      the MessageSourceAware for internationalization resource acquisition module
      ApplicationContextAware container, to obtain a container
  3.5 ignored Bean automatic assembly interfaces, which has been the post-processor ApplicationContextAwareProcessor
  3.6 automatic assembling rules provided Bean (correspondence relation), a class provided during assembly Bean desired
    beanFactory.registerResolvableDependency ( ApplicationContext.class, this);
    for example: @Autowired container injects this current container i.e.
       Private the applicationContext applicationContext;
  3.7 registered Bean postprocessor ApplicationListenerDetector, for processing ApplicationEvent interface implementation classes, these classes will be registered to the vessel and event broadcasts reactor
  3.8 Register Bean postprocessor LoadTimeWeaverAwareProcessor, if included loadTimeWeaver named class, are used for the treatment Bean LoadTimeWeaverAware interface and set temporary class loader ContextTypeMatchClassLoader
  3.9 registered vessel Bean (Environment, systemProperties, systemEnvironment)
. 4 postProcessBeanFactory (beanFactory ); BeanFactory post initialization event (empty implementation for subclasses to implement)
. 5 invokeBeanFactoryPostProcessors (beanFactory); BeanFactory postprocessor performs
  NOTE: BeanFactory postprocessor there are two types: BeanDefinitionRegistryPostProcessor and the BeanFactoryPostProcessor
  5.1 PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors (beanFactory, getBeanFactoryPostProcessors ());
    the getBeanFactoryPostProcessors () is manually injected BeanFactory postprocessor empty by default
    5.1.1 Get BeanFactory postprocessor manual injection, if the processor type is performed BeanDefinitionRegistryPostProcessor postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry) Method
    5.1.2 BeanDefinitionRegistryPostProcessor obtain all types of post-processor from the container, and in accordance with PriorityOrdered-> Ordered- > NonOrdered order of execution
    5.1.3 post implantation BeanFactoryPostProcessor processor to perform a manual type, call postProcessBeanFactory (ConfigurableListableBeanFactory beanFactory) method
    5.1.4 BeanFactoryPostProcessor obtain all types of post-processor from the container, and in accordance with PriorityOrdered-> Ordered -> the execution order NonOrdered
  5.2 because classes can manually register BeanFactory the post processor, the operation repeats step 3.8, there is again determined whether a class named loadTimeWeaver, any post-processor register LoadTimeWeaverAwareProcessor, and sets the temporary class loader ContextTypeMatchClassLoader
. 6 registerBeanPostProcessors (beanFactory); post-processor register of Bean
  6.1 Get all types of post-processor BeanPostProcessor from the container, the classification processor PriorityOrdered, Ordered, Internal, NonOrdered
    according PriorityOrdered-> Ordered-> NonOrdered-> Internal sequence sequentially registered post processor Bean
  6.2 reregister the Bean postprocessor ApplicationListenerDetector, the processor to the last, first registration see 3.7
7 initMessageSource (); initialization international resource class
  7.1 Bean interpretation of whether there is a vessel named messageSource
  7.2, if any, to initialize it, if the HierarchicalMessageSource implement an interface, and the parent MessageSource does not exist, obtaining a parent injection internal MessageSource
  7.3 If not, the initialization DelegatingMessageSource, to set the interior of the parent MessageSource, and injected into the container Spring
8 initApplicationEventMulticaster (); application initialization event broadcaster for the event dispatch
  8.1 to determine whether there called applicationEventMulticaster container Bean
  8.2, if any, to initialize it
  8.3 if not, initialize SimpleApplicationEventMultic ASTER, and injected into the container Spring
9 onRefresh (); a refresh event (empty implementation, to achieve for subclasses)
10 registerListeners (); registered ApplicationListener
  10.1 acquiring application event broadcaster (ApplicationEventMulticaster), was created in step 8
  10.2 acquiring manual registration of ApplicationListener, which in turn is injected into ApplicationEventMulticaster
  10.3 acquiring container all ApplicationListener, which in turn is injected into ApplicationEventMulticaster
  10.4 acquired early application event collection step 1.4 is defined (if pushed through the container prior to the event, will be stored in the set), first data cache to a local variable, and the assignment set to NULL, NULL is assigned to to prevent the push event is still stored in the collection (judgment based on whether the collection is NULL).
  10.5 ApplicationEventMulticaster ApplicationListener in turn call onApplicationEvent (E event) interfaces
11 finishBeanFactoryInitialization (beanFactory); all non-singleton initialization delay loading of Bean
  11.1 ConversionService if contained in the container, the set value of BeanFacotry ConversionService of
  11.2 when the container is not provided expression parser EmbeddedValueResolverAware, the expression parser initialization container, the default StringValueResolver
  11.3 initialization Bean LoadTimeWeaverAware interface
  11.4 Empty temporary class loader, 3.8 and 5.2 will set the value
  11.5 freeze configured configurationFrozen = true; when you call getBeanNamesForType (), will determine the value, Ruoyi freeze will only get information in the cache.
  11.6 non-initialization of singleton lazy loading Bean
    11.6.1 cycle through all description Bean, Bean if non-abstract, singleton, non-delayed loading, it will be created
    11.6.2 If the Bean implements the interface FactoryBean
      11.6.2.1 call getBean ( "$" + beanName) method
      11.6.2.2 Bean determines whether to implement the interface and SmartFactoryBean isEagerInit () returns true, the call to the getBean (the beanName)
      11.6.3 if the Bean FactoryBean not implement the interface
        call getBean (beanName), getBean implemented method subsequent supplementary
  after 11.7 Bean initializes all non-delay singleton loading is completed, if implemented sequentially to see if the call interface SmartInitializingSingleton afterSingletonsInstantiated () method
12 finishRefresh (); complete refresh
  12.1 lifecycle initialization processor LifecycleProcessor, if present in the container initialization, otherwise, set the default DefaultLifecycleProcessor
  12.2 calls LifecycleProcessor of onRefresh () method
  12.3 promote container complete refresh event
13 resetCommonCaches (); remove all kinds of cache




Guess you like

Origin www.cnblogs.com/zhuqianchang/p/11413594.html