测试用例1
一个简单的springboot工程,在MainApplication上标注@MapperScan(“com.example.mapper”)
@MapperScan("com.example.mapper") //扫描的mapper
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
测试用例2
在mapper路径下建一个UserMapper接口
@Repository
public interface UserMapper {
User Sel(int id);
}
收集启动类的@MapperScan注解对应的Import类
将断点打到ConfigurationClassParser$SourceClass.getAnnotationAttributes方法,则代码执行过程如下
代码块1:main
运行
package com.example;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan("com.example.mapper") //扫描的mapper
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
"(1) 运行"
}
}
代码块2:run
运行
参数:args=[]
参数:primarySource=class com.example.DemoApplication
package org.springframework.boot;
public class SpringApplication {
public static ConfigurableApplicationContext run(Class<?> primarySource, //args=[];primarySource=class com.example.DemoApplication;
String... args) {
return run(new Class<?>[] { primarySource }, args); //程序启动入口
"(2) 运行"
"参数:args=[]"
"参数:primarySources=class com.example.DemoApplication,"
"程序启动入口"
}
}
代码块3:run
运行
参数:args=[]
参数:primarySources=class com.example.DemoApplication,
package org.springframework.boot;
public class SpringApplication {
public static ConfigurableApplicationContext run(Class<?>[] primarySources, //args=[];primarySources=class com.example.DemoApplication,;
String[] args) {
return new SpringApplication(primarySources).run(args); //new 了一个 SpringApplication,然后执行 run 方法
"(3) 运行"
"参数:args=[]"
"new 了一个 SpringApplication,然后执行 run 方法"
}
}
代码块4:run
刷新上下文
参数:args=[]
package org.springframework.boot;
public class SpringApplication {
public ConfigurableApplicationContext run(String... args) { //args=[];
......
refreshContext(context); //s刷新容器;ioc容器初始化(如果是web应用还会创建嵌入式的Tomcat);Spring注解版扫描,创建,加载所有组件的地方;(配置类,组件,自动配置)
"(4) 刷新上下文"
"s刷新容器;ioc容器初始化(如果是web应用还会创建嵌入式的Tomcat);Spring注解版扫描,创建,加载所有组件的地方;(配置类,组件,自动配置)"
......
}
}
代码块5:refreshContext
刷新
package org.springframework.boot;
public class SpringApplication {
private void refreshContext(ConfigurableApplicationContext context) {
refresh(context); //调用 AbstractApplication#refresh 方法,去初始化IOC容器
"(5) 刷新"
"调用 AbstractApplication#refresh 方法,去初始化IOC容器"
......
}
}
代码块6:refresh
刷新
package org.springframework.boot;
public class SpringApplication {
protected void refresh(ApplicationContext applicationContext) {
......
((AbstractApplicationContext) applicationContext).refresh(); //强转为父类方法执行
"(6) 刷新"
"强转为父类方法执行"
}
}
代码块7:refresh
刷新
package org.springframework.boot.web.servlet.context;
public class ServletWebServerApplicationContext extends GenericWebApplicationContext implements ConfigurableWebServerApplicationContext{
@Override
public final void refresh() throws BeansException, IllegalStateException {
......
super.refresh(); //执行刷新!
"(7) 刷新"
"执行刷新!"
......
}
}
代码块8:refresh
调用Bean工厂后处理器
package org.springframework.context.support;
public class AbstractApplicationContext extends DefaultResourceLoader implements ConfigurableApplicationContext{
@Override
public void refresh() throws BeansException, IllegalStateException {
......
invokeBeanFactoryPostProcessors(beanFactory); //5. 执行BeanFactory各种PostProcessor处理器 org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;
"(8) 调用Bean工厂后处理器"
"参数:beanFactory=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication]; root of factory hierarchy"
"5. 执行BeanFactory各种PostProcessor处理器 org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;"
......
}
}
代码块9:invokeBeanFactoryPostProcessors
调用Bean工厂后处理器
参数:beanFactory=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springfra…
package org.springframework.context.support;
public class AbstractApplicationContext extends DefaultResourceLoader implements ConfigurableApplicationContext{
protected void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory) { //beanFactory=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication]; root of factory hierarchy;
PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(beanFactory, getBeanFactoryPostProcessors()); //2.invokeBeanFactoryPostProcessors: 实例化并调用所有已注册的BeanFactoryPostProcessor org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;
"(9) 调用Bean工厂后处理器"
"参数:beanFactory=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication]; root of factory hierarchy"
"2.invokeBeanFactoryPostProcessors: 实例化并调用所有已注册的BeanFactoryPostProcessor org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;"
......
}
}
代码块10:invokeBeanFactoryPostProcessors
调用注册Bean定义后置处理器
参数:beanFactory=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springfra…
package org.springframework.context.support;
public class PostProcessorRegistrationDelegate {
public static void invokeBeanFactoryPostProcessors( //beanFactory=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication]; root of factory hierarchy;
ConfigurableListableBeanFactory beanFactory, List<BeanFactoryPostProcessor> beanFactoryPostProcessors) {
......
invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry); //5.4 遍历currentRegistryProcessors, 执行postProcessBeanDefinitionRegistry方法 org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;
"(10) 调用注册Bean定义后置处理器"
"参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory]; root of factory hierarchy"
"5.4 遍历currentRegistryProcessors, 执行postProcessBeanDefinitionRegistry方法 org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;"
......
}
}
代码块11:invokeBeanDefinitionRegistryPostProcessors
调用注册Bean定义后置处理器方法
参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframew…
package org.springframework.context.support;
public class PostProcessorRegistrationDelegate {
private static void invokeBeanDefinitionRegistryPostProcessors( //registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory]; root of factory hierarchy;
Collection<? extends BeanDefinitionRegistryPostProcessor> postProcessors, BeanDefinitionRegistry registry) {
......
postProcessor.postProcessBeanDefinitionRegistry(registry); //就一个ConfigurationClassPostProcessor org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;
"(11) 调用注册Bean定义后置处理器方法"
"参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory]; root of factory hierarchy"
"就一个ConfigurationClassPostProcessor org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;"
......
}
}
代码块12:postProcessBeanDefinitionRegistry
处理配置类bean定义
参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframew…
package org.springframework.context.annotation;
public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor{
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) { //registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory]; root of factory hierarchy;
......
processConfigBeanDefinitions(registry); //2. 开始解析 org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;
"(12) 处理配置类bean定义"
"参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory]; root of factory hierarchy"
"2. 开始解析 org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.http-org.springframework.boot.autoconfigure.http.HttpProperties,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,taskExecutorBuilder,applicationTaskExecutor,spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,formContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigu;"
}
}
代码块13:processConfigBeanDefinitions
解析
参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframew…
package org.springframework.context.annotation;
public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor{
public void processConfigBeanDefinitions(BeanDefinitionRegistry registry) { //registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory]; root of factory hierarchy;
......
parser.parse(candidates); //4.1 解析候选的BeanDefinition 为 Configuration Class
"(13) 解析"
"4.1 解析候选的BeanDefinition 为 Configuration Class"
......
}
}
代码块14:parse
解析
package org.springframework.context.annotation;
public class ConfigurationClassParser {
public void parse(Set<BeanDefinitionHolder> configCandidates) {
......
parse(((AnnotatedBeanDefinition) bd).getMetadata(), holder.getBeanName()); //其实内部调用都是processConfigurationClass进行解析的
"(14) 解析"
"参数:beanName=demoApplication"
"其实内部调用都是processConfigurationClass进行解析的"
......
}
}
代码块15:parse
处理配置类
参数:beanName=demoApplication
package org.springframework.context.annotation;
public class ConfigurationClassParser {
protected final void parse(AnnotationMetadata metadata, String beanName) throws IOException { //beanName=demoApplication;
processConfigurationClass(new ConfigurationClass(metadata, beanName)); //把我们的配置类源信息和beanName包装成一个ConfigurationClass对象
"(15) 处理配置类"
"参数:configClass=ConfigurationClass: beanName 'demoApplication', com.example.DemoApplication"
"把我们的配置类源信息和beanName包装成一个ConfigurationClass对象"
}
}
代码块16:processConfigurationClass
处理配置类
参数:configClass=ConfigurationClass: beanName ‘demoApplication’, com.example.DemoApplication
package org.springframework.context.annotation;
public class ConfigurationClassParser {
protected void processConfigurationClass(ConfigurationClass configClass) throws IOException { //configClass=ConfigurationClass: beanName 'demoApplication', com.example.DemoApplication;
......
sourceClass = doProcessConfigurationClass(configClass, sourceClass); //【真正解析配置类】
"(16) 处理配置类"
"参数:sourceClass=com.example.DemoApplication"
"参数:configClass=ConfigurationClass: beanName 'demoApplication', com.example.DemoApplication"
"【真正解析配置类】"
......
}
}
代码块17:doProcessConfigurationClass
处理配置类的@Import注解
参数:sourceClass=com.example.DemoApplication
参数:configClass=ConfigurationClass: beanName ‘demoApplication’, com.example.DemoApplication
package org.springframework.context.annotation;
public class ConfigurationClassParser {
@Nullable
protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) //sourceClass=com.example.DemoApplication;configClass=ConfigurationClass: beanName 'demoApplication', com.example.DemoApplication;
throws IOException {
......
processImports(configClass, sourceClass, getImports(sourceClass), true); //处理@Import注解 configClass=ConfigurationClass: beanName 'demoApplication', com.example.DemoApplication; sourceClass=com.example.DemoApplication;
"(17) 处理配置类的@Import注解"
"参数:sourceClass=com.example.DemoApplication"
"处理@Import注解 configClass=ConfigurationClass: beanName 'demoApplication', com.example.DemoApplication; sourceClass=com.example.DemoApplication;"
......
}
}
代码块18:getImports
收集import配置类
参数:sourceClass=com.example.DemoApplication
package org.springframework.context.annotation;
public class ConfigurationClassParser {
private Set<SourceClass> getImports(SourceClass sourceClass) throws IOException { //sourceClass=com.example.DemoApplication;
......
collectImports(sourceClass, imports, visited); //1.处理解析类中的@Import sourceClass=com.example.DemoApplication;
"(18) 收集import配置类"
"参数:sourceClass=com.example.DemoApplication"
"1.处理解析类中的@Import sourceClass=com.example.DemoApplication;"
......
}
}
代码块19:collectImports
收集import配置类
参数:sourceClass=com.example.DemoApplication
package org.springframework.context.annotation;
public class ConfigurationClassParser {
private void collectImports(SourceClass sourceClass, Set<SourceClass> imports, Set<SourceClass> visited) //sourceClass=com.example.DemoApplication;
throws IOException {
......
collectImports(annotation, imports, visited); //进行递归,比如 @Enable*** annotation=org.springframework.boot.autoconfigure.SpringBootApplication; annotation=org.mybatis.spring.annotation.MapperScan;
"(19) 收集import配置类"
"参数:sourceClass=org.mybatis.spring.annotation.MapperScan"
"进行递归,比如 @Enable*** annotation=org.springframework.boot.autoconfigure.SpringBootApplication; annotation=org.mybatis.spring.annotation.MapperScan;"
......
}
}
代码块20:collectImports
获取注解属性
参数:sourceClass=org.mybatis.spring.annotation.MapperScan
package org.springframework.context.annotation;
public class ConfigurationClassParser {
private void collectImports(SourceClass sourceClass, Set<SourceClass> imports, Set<SourceClass> visited) //sourceClass=org.mybatis.spring.annotation.MapperScan;
throws IOException {
......
imports.addAll(sourceClass.getAnnotationAttributes(Import.class.getName(), "value")); //收集所有的导入配置类
"(20) 获取注解属性@Import(MapperScannerRegistrar.class)"
"参数:attribute=value"
"参数:annType=org.springframework.context.annotation.Import"
"收集所有的导入配置类"
......
}
}
代码块21:getAnnotationAttributes
获取MapperScannerRegistrar的完整包名类名
参数:attribute=value
参数:annType=org.springframework.context.annotation.Import
package org.springframework.context.annotation;
public class ConfigurationClassParser {
public Collection<SourceClass> getAnnotationAttributes(String annType, String attribute) throws IOException { //attribute=value;annType=org.springframework.context.annotation.Import;
......
String[] classNames = (String[]) annotationAttributes.get(attribute); //获取属性获取 ClassName 简单说获取的就是 ImportBean 的全限定类名 classNames=org.mybatis.spring.annotation.MapperScannerRegistrar,;
"(21) 获取MapperScannerRegistrar的完整包名类名"
"获取属性获取 ClassName 简单说获取的就是 ImportBean 的全限定类名 classNames=org.mybatis.spring.annotation.MapperScannerRegistrar,;"
......
}
}
小结:调用栈
收集启动类的@MapperScan注解对应的Import类
- springboot原理.springboot原理
- SpringApplication.run()
- SpringApplication.run()
- SpringApplication.run()
- SpringApplication.refreshContext()
- SpringApplication.refresh()
- ServletWebServerApplicationContext.refresh()
- AbstractApplicationContext.refresh()
- AbstractApplicationContext.invokeBeanFactoryPostProcessors()
- PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors()
- PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors()
- ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry()
- ConfigurationClassPostProcessor.processConfigBeanDefinitions()
- ConfigurationClassParser.parse()
- ConfigurationClassParser.parse()
- ConfigurationClassParser.processConfigurationClass()
- ConfigurationClassParser.doProcessConfigurationClass()
- ConfigurationClassParser.getImports()
- ConfigurationClassParser.collectImports()
- ConfigurationClassParser.collectImports()
- ConfigurationClassParser$SourceClass.getAnnotationAttributes()
调用MapperScannerRegistrar的注册bean定义方法,收集候选组件
将断点打到ClassPathScanningCandidateComponentProvider.scanCandidateComponents方法,则代码执行过程如下
代码块22:processConfigBeanDefinitions
加载Bean定义
参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframew…
package org.springframework.context.annotation;
public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor{
public void processConfigBeanDefinitions(BeanDefinitionRegistry registry) { //registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory]; root of factory hierarchy;
......
parser.parse(candidates);
"(13)"
this.reader.loadBeanDefinitions(configClasses); //4.3 加载Configuration Class
"(22) 加载Bean定义"
"4.3 加载Configuration Class"
......
}
}
代码块23:loadBeanDefinitions
加载Configuration类的Bean定义
package org.springframework.context.annotation;
public class ConfigurationClassBeanDefinitionReader {
public void loadBeanDefinitions(Set<ConfigurationClass> configurationModel) {
......
loadBeanDefinitionsForConfigurationClass(configClass, trackedConditionEvaluator); //调用这个方法完成的加载 configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/web/embedded/EmbeddedWebServerFactoryCustomizerAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration', class path resource [org/springframework/boot/autoconfigure/web/embedded/EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$TransactionTemplateConfiguration', class path resource [org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration$TransactionTemplateConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$EnableTransactionManagementConfiguration', class path resource [org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration$EnableTransactionManagementConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$EnableTransactionManagementConfiguration$CglibAutoProxyConfiguration', class path resource [org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration$EnableTransactionManagementConfiguration$CglibAutoProxyConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration', class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$DataSourceTransactionManagerConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration$DataSourceTransactionManagerConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration$NamedParameterJdbcTemplateConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration$NamedParameterJdbcTemplateConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration$JdbcTemplateConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration$JdbcTemplateConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration$JacksonCodecConfiguration', class path resource [org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfiguration$JacksonCodecConfiguration.class];
"(23) 加载Configuration类的Bean定义"
"参数:configClass=ConfigurationClass: beanName 'demoApplication', com.example.DemoApplication"
"调用这个方法完成的加载 configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/web/embedded/EmbeddedWebServerFactoryCustomizerAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration', class path resource [org/springframework/boot/autoconfigure/web/embedded/EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$TransactionTemplateConfiguration', class path resource [org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration$TransactionTemplateConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$EnableTransactionManagementConfiguration', class path resource [org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration$EnableTransactionManagementConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$EnableTransactionManagementConfiguration$CglibAutoProxyConfiguration', class path resource [org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration$EnableTransactionManagementConfiguration$CglibAutoProxyConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration', class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$DataSourceTransactionManagerConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration$DataSourceTransactionManagerConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration$NamedParameterJdbcTemplateConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration$NamedParameterJdbcTemplateConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration$JdbcTemplateConfiguration', class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration$JdbcTemplateConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfiguration.class]; configClass=ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration$JacksonCodecConfiguration', class path resource [org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfiguration$JacksonCodecConfiguration.class];"
......
}
}
代码块24:loadBeanDefinitionsForConfigurationClass
从注册器加载Bean定义
参数:configClass=ConfigurationClass: beanName ‘demoApplication’, com.example.DemoApplication
package org.springframework.context.annotation;
public class ConfigurationClassBeanDefinitionReader {
private void loadBeanDefinitionsForConfigurationClass( //configClass=ConfigurationClass: beanName 'demoApplication', com.example.DemoApplication;
ConfigurationClass configClass, TrackedConditionEvaluator trackedConditionEvaluator) {
......
loadBeanDefinitionsFromRegistrars(configClass.getImportBeanDefinitionRegistrars()); //处理ImportBeanDefinitionRegistrar
"(24) 从注册器加载Bean定义"
"参数:registrars=org.mybatis.spring.annotation.MapperScannerRegistrar@16eccb2e=org.springframework.core.type.StandardAnnotationMetadata@11ce2e22;org.springframework.boot.autoconfigure.AutoConfigurationPackages$Registrar@5ef5c734=org.springframework.core.type.StandardAnnotationMetadata@11ce2e22;"
"处理ImportBeanDefinitionRegistrar"
}
}
代码块25:loadBeanDefinitionsFromRegistrars
注册Bean定义
参数:registrars=org.mybatis.spring.annotation.MapperScannerRegistrar@16eccb2e=org.springframework.core.type.StandardAnnotatio…
package org.springframework.context.annotation;
public class ConfigurationClassBeanDefinitionReader {
private void loadBeanDefinitionsFromRegistrars(Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> registrars) { //registrars=org.mybatis.spring.annotation.MapperScannerRegistrar@16eccb2e=org.springframework.core.type.StandardAnnotationMetadata@11ce2e22;org.springframework.boot.autoconfigure.AutoConfigurationPackages$Registrar@5ef5c734=org.springframework.core.type.StandardAnnotationMetadata@11ce2e22;;
registrars.forEach((registrar, metadata) ->
"(25) 注册Bean定义"
"参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService]; root of factory hierarchy"
......
}
}
代码块26:registerBeanDefinitions
执行扫描
参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframew…
package org.mybatis.spring.annotation;
public class MapperScannerRegistrar implements ImportBeanDefinitionRegistrar{
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { //registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService]; root of factory hierarchy;
......
scanner.doScan(StringUtils.toStringArray(basePackages)); //主要解析工作了
"(26) 执行扫描"
"参数:basePackages=com.example.mapper,"
"主要解析工作了"
}
}
代码块27:doScan
执行扫描
参数:basePackages=com.example.mapper,
package org.mybatis.spring.mapper;
public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner{
@Override
public Set<BeanDefinitionHolder> doScan(String... basePackages) { //basePackages=com.example.mapper,;
Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages); //调用 ClassPathBeanDefinitionScanner#doScan 方法
"(27) 执行扫描"
"参数:basePackages=com.example.mapper,"
"调用 ClassPathBeanDefinitionScanner#doScan 方法"
......
}
}
代码块28:doScan
查找候选组件
参数:basePackages=com.example.mapper,
package org.springframework.context.annotation;
public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateComponentProvider{
protected Set<BeanDefinitionHolder> doScan(String... basePackages) { //basePackages=com.example.mapper,;
......
Set<BeanDefinition> candidates = findCandidateComponents(basePackage); //2.扫描basePackage,将符合要求的bean定义全部找出来(这边符合要求最常见的就是使用Component注解)
"(28) 查找候选组件"
"参数:basePackage=com.example.mapper"
"2.扫描basePackage,将符合要求的bean定义全部找出来(这边符合要求最常见的就是使用Component注解)"
......
}
}
代码块29:findCandidateComponents
扫描候选组件
参数:basePackage=com.example.mapper
package org.springframework.context.annotation;
public class ClassPathScanningCandidateComponentProvider implements EnvironmentCapable{
public Set<BeanDefinition> findCandidateComponents(String basePackage) { //basePackage=com.example.mapper;
......
return scanCandidateComponents(basePackage); //这里是关键
"(29) 扫描候选组件"
"参数:basePackage=com.example.mapper"
"这里是关键"
......
}
}
代码块30:scanCandidateComponents
将扫描到的bean定义添加到候选组件
参数:basePackage=com.example.mapper
package org.springframework.context.annotation;
public class ClassPathScanningCandidateComponentProvider implements EnvironmentCapable{
private Set<BeanDefinition> scanCandidateComponents(String basePackage) { //basePackage=com.example.mapper;
......
candidates.add(sbd); //7.确定是候选类,则添加到candidates sbd=Generic bean: class [com.example.mapper.UserMapper]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class];
"(30) 将扫描到的bean定义添加到候选组件"
"7.确定是候选类,则添加到candidates sbd=Generic bean: class [com.example.mapper.UserMapper]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class];"
......
}
}
小结:调用栈
调用MapperScannerRegistrar的注册bean定义方法,收集候选组件
- springboot原理.springboot原理
- SpringApplication.run()
- SpringApplication.run()
- SpringApplication.run()
- SpringApplication.refreshContext()
- SpringApplication.refresh()
- ServletWebServerApplicationContext.refresh()
- AbstractApplicationContext.refresh()
- AbstractApplicationContext.invokeBeanFactoryPostProcessors()
- PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors()
- PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors()
- ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry()
- ConfigurationClassPostProcessor.processConfigBeanDefinitions()
- ConfigurationClassBeanDefinitionReader.loadBeanDefinitions()
- ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass()
- ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars()
- MapperScannerRegistrar.registerBeanDefinitions()
- ClassPathMapperScanner.doScan()
- ClassPathBeanDefinitionScanner.doScan()
- ClassPathScanningCandidateComponentProvider.findCandidateComponents()
- ClassPathScanningCandidateComponentProvider.scanCandidateComponents()
注册bean定义
将断点打到DefaultListableBeanFactory.registerBeanDefinition方法,则代码执行过程如下
代码块31:doScan
注册Bean定义
参数:basePackages=com.example.mapper,
package org.springframework.context.annotation;
public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateComponentProvider{
protected Set<BeanDefinitionHolder> doScan(String... basePackages) { //basePackages=com.example.mapper,;
......
Set<BeanDefinition> candidates = findCandidateComponents(basePackage);
"(28)"
registerBeanDefinition(definitionHolder, this.registry); //11.注册BeanDefinition(注册到beanDefinitionMap、beanDefinitionNames、aliasMap缓存) definitionHolder=Bean definition with name 'userMapper': Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class];
"(31) 注册Bean定义"
"参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService]; root of factory hierarchy"
"参数:definitionHolder=Bean definition with name 'userMapper': Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class]"
"11.注册BeanDefinition(注册到beanDefinitionMap、beanDefinitionNames、aliasMap缓存) definitionHolder=Bean definition with name 'userMapper': Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class];"
......
}
}
代码块32:registerBeanDefinition
注册Bean定义
参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframew…
参数:definitionHolder=Bean definition with name ‘userMapper’: Generic bean: class [com.example.mapper.UserMapper]; scope=sing…
package org.springframework.context.annotation;
public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateComponentProvider{
protected void registerBeanDefinition(BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry) { //registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService]; root of factory hierarchy;definitionHolder=Bean definition with name 'userMapper': Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class];
BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, registry); //调用BeanDefinitionReaderUtils工具类来完成BeanDefinition的注册 definitionHolder=Bean definition with name 'userMapper': Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class]; registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper]; root of factory hierarchy;
"(32) 注册Bean定义"
"参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService]; root of factory hierarchy"
"参数:definitionHolder=Bean definition with name 'userMapper': Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class]"
"调用BeanDefinitionReaderUtils工具类来完成BeanDefinition的注册 definitionHolder=Bean definition with name 'userMapper': Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class]; registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService,userMapper]; root of factory hierarchy;"
}
}
代码块33:registerBeanDefinition
注册Bean定义
参数:registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframew…
参数:definitionHolder=Bean definition with name ‘userMapper’: Generic bean: class [com.example.mapper.UserMapper]; scope=sing…
package org.springframework.beans.factory.support;
public class BeanDefinitionReaderUtils {
public static void registerBeanDefinition( //registry=org.springframework.beans.factory.support.DefaultListableBeanFactory@73e9cf30: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,demoApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,userController,userService]; root of factory hierarchy;definitionHolder=Bean definition with name 'userMapper': Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class];
BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry)
throws BeanDefinitionStoreException {
......
registry.registerBeanDefinition(beanName, definitionHolder.getBeanDefinition()); //2.注册beanName、BeanDefinition到缓存中(核心逻辑),实现类为; DefaultListableBeanFactory beanName=userMapper;
"(33) 注册Bean定义"
"参数:beanDefinition=Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class]"
"参数:beanName=userMapper"
"2.注册beanName、BeanDefinition到缓存中(核心逻辑),实现类为; DefaultListableBeanFactory beanName=userMapper;"
......
}
}
代码块34:registerBeanDefinition
将userMapper的bean定义存入缓存
参数:beanDefinition=Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; aut…
参数:beanName=userMapper
package org.springframework.beans.factory.support;
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements ConfigurableListableBeanFactory{
@Override
public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) //beanDefinition=Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class];beanName=userMapper;
throws BeanDefinitionStoreException {
......
this.beanDefinitionMap.put(beanName, beanDefinition); //将本次传进来的beanName 和 BeanDefinition映射放入beanDefinitionMap缓存 beanName=userMapper; beanDefinition=Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class];
"(34) 将userMapper的bean定义存入缓存"
"将本次传进来的beanName 和 BeanDefinition映射放入beanDefinitionMap缓存 beanName=userMapper; beanDefinition=Generic bean: class [com.example.mapper.UserMapper]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\project\Springboot_Mybatis\target\classes\com\example\mapper\UserMapper.class];"
......
}
}
小结:调用栈
注册bean定义
- springboot原理.springboot原理
- SpringApplication.run()
- SpringApplication.run()
- SpringApplication.run()
- SpringApplication.refreshContext()
- SpringApplication.refresh()
- ServletWebServerApplicationContext.refresh()
- AbstractApplicationContext.refresh()
- AbstractApplicationContext.invokeBeanFactoryPostProcessors()
- PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors()
- PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors()
- ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry()
- ConfigurationClassPostProcessor.processConfigBeanDefinitions()
- ConfigurationClassBeanDefinitionReader.loadBeanDefinitions()
- ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass()
- ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars()
- MapperScannerRegistrar.registerBeanDefinitions()
- ClassPathMapperScanner.doScan()
- ClassPathBeanDefinitionScanner.doScan()
- ClassPathBeanDefinitionScanner.registerBeanDefinition()
- BeanDefinitionReaderUtils.registerBeanDefinition()
- DefaultListableBeanFactory.registerBeanDefinition()