Spring源码时序图
2021-04-08 09:14:55 1 举报
一条线串联了Spring的核心流程
作者其他创作
大纲/内容
JdkDynamicAopProxy
FrameworkServlet
Aop
applyBeanPostProcessorsAfterInitialization()
refreshBeanFactory()
wrapIfNecessary()
populateBean()
initHandlerAdapters
onRefresh
ProxyFactory
onRefresh()
DefaultBeanDefinitionDocumentReader
loadBeanDefinitions(reader)
createWebApplicationContext()
反射获取实例,并返回BeanWrapper
MVC
registerBeanDefinition
render()
doService
JdkDynamicAopProxy/CglibAopProxy
initHandlerMappings
createBeanFactory()
责任链调用
BeanWrapperImpl
getBean()
initStrategies
dm.interceptor.invoke(this);
初始化阶段
finishBeanFactoryInitialization(beanFactory);
createBeanInstance
preInstantiateSingletons()
parseDefaultElement
doGetBean()
configureAndRefreshWebApplicationContext()
AbstractPropertyAccessor
createProxy()
obtainFreshBeanFactory()
refresh()
findWebApplicationContext()
AbstractApplicationContext
XmlBeanDefinitionReader
instantiateBean
AbstractAutowireCapableBeanFactory
instantiate()
HttpServletBean
AbstractHandlerMethodAdapter
createAopProxy()
MethodBeforeAdviceInterceptor/AfterReturningAdviceInterceptor
RequestMappingHandlerAdapter
initWebApplicationContext()
AdvisedSupport
若该类有接口实现,选择JDK代理,否则返回CgLib代理
init()
setPropertyValue()
registerBeanDefinitions
postProcessAfterInitialization()
获取所有的Advisors
initServletBean
invokeHandlerMethod()
初始化策略
DispatcherServlet
Client
proceed()
获取XmlWebApplicationContext容器,并进行赋值
注入
ReflectiveMethodInvocation
打印Tomcat项目日志,启动的方法是ContextLoader.initWebApplicationContext()
initViewResolvers
handle()
查找Web容器,若没有则创建默认空的父容器WebAppliationContext
XmlWebApplicationContext
setValue()
proxyFactory.getProxy()
processLocalProperty()
DefaultListableBeanFactory
DI
handleInternal()
ProxyCreatorSupport
doDispatch()
doRegisterBeanDefinitions
AbstractRefreshableApplicationContext
loadBeanDefinitions()
创建beanFactory= DefaultListableBeanFactory
//多文件上传的组件 initMultipartResolver(context); //初始化本地语言环境 initLocaleResolver(context); //初始化模板处理器 initThemeResolver(context); //handlerMapping initHandlerMappings(context); //初始化参数适配器 initHandlerAdapters(context); //初始化异常拦截器 initHandlerExceptionResolvers(context); //初始化视图预处理器 initRequestToViewNameTranslator(context); //初始化视图转换器 initViewResolvers(context); //FlashMap管理器 initFlashMapManager(context);
AbstractAdvisorAutoProxyCreator
织入
getProxy()
invoke()
doLoadBeanDefinitions
loadBeanDefinitions(configLocation);configLocation:优先取configLocations,默认为/WEB-INF/applicationContext.xml
getHandlerAdapter()
AbstractAutoProxyCreator
setPropertyValues()
getHandler()
createBean()
processDispatchResult()
initializeBean
AbstractNestablePropertyAccessor
AbstractView
getAdvicesAndAdvisorsForBean()
实例化
SimpleInstantiationStrategy
IoC
applyPropertyValues()
parseBeanDefinitions
processBeanDefinition
创建代理类
doCreateBean
AbstractBeanFactory
预加载,默认Bean为饿汉式单例。可以设置lazyInit=true懒汉式加载。
getInterceptorsAndDynamicInterceptionAdvice()
收藏
收藏
0 条评论
下一页