SpringMVC深度解析
2020-03-16 14:04:34 0 举报
AI智能生成
springmvc源码深度解析
作者其他创作
大纲/内容
MEAT-INF/service/
ServletContainerInitializer
SpringServletContainerInitializer
@HandlesTypes(WebApplicationInitializer.class)
onStartup
方法内容
webAppInitializerClasses != null
for (Class<?> waiClass : webAppInitializerClasses)
ReflectionUtils.accessibleConstructor(waiClass).newInstance()
initializers.add((WebApplicationInitializer)
AnnotationAwareOrderComparator.sort(initializers);
initializer.onStartup(servletContext);
super.onStartup(servletContext)
AbstractContextLoaderInitializer
registerContextLoaderListener(servletContext)
createRootApplicationContext()
getRootConfigClasses()
new AnnotationConfigWebApplicationContext()
context.register(configClasses);
return context
new ContextLoaderListener(rootAppContext)
listener.setContextInitializers(getRootApplicationContextInitializers())
getRootApplicationContextInitializers
servletContext.addListener(listener)
registerDispatcherServlet(servletContext)
createServletApplicationContext()
new AnnotationConfigWebApplicationContext()
getServletConfigClasses()
context.register(configClasses)
return context
createDispatcherServlet(servletAppContext)
new DispatcherServlet(servletAppContext)
super(webApplicationContext)
setDispatchOptionsRequest(true)
setContextInitializers(getServletApplicationContextInitializers())
servletContext.addServlet(servletName, dispatcherServlet)
registration.setLoadOnStartup(1)
registration.addMapping(getServletMappings())
setAsyncSupported(isAsyncSupported())
customizeRegistration
校验
!waiClass.isInterface()
!Modifier.isAbstract(waiClass.getModifiers()
WebApplicationInitializer.class.isAssignableFrom(waiClass)
参数
Set<Class<?>> webAppInitializerClasses
ServletContext servletContext
ContextLoader
initWebApplicationContext
this.context == null
ConfigurableWebApplicationContext
ConfigurableWebApplicationContext
!cwac.isActive()
cwac.getParent() == null
loadParentContext(servletContext);
cwac.setParent(parent)
configureAndRefreshWebApplicationContext(cwac, servletContext);
sc.getInitParameter(CONTEXT_ID_PARAM)
idParam != null
wac.setServletContext(sc)
initPropertySources(sc, null);
wac.refresh()
0 条评论
下一页