springMvc DispatcherServlet的初始化过程

1.web.xml文件配置:

 

<servlet>
<servlet-name>chapter2</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet-config.xml</param-value>
</init-param>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-common-config.xml,
classpath:spring-budget-config.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

web.xml配置说明:

 

在web容器加载时

ContextLoaderListener加载的为context-param中的配置,DispatcherServlet加载的是如图init-param中的配置,他们的配置不能重叠否则会重复加载对象,如果context-param中的配置,DispatcherServlet加载的是如图init-param中的配置,他们的配置不能重叠否则会重复加载对象,如果
DispatcherServlet中已经加载了所有需要的对象,ContextLoaderListener可以不配置ContextLoaderListener可以不配置

 

 

 

 


2.流程图:

 

 

初始化循序如后台显示:

 

信息: Initializing Spring root WebApplicationContext //由 ContextLoaderListener启动ROOT上下文
2012-03-12 13:33:55 [main] INFO org.springframework.web.context.ContextLoader - Root
WebApplicationContext: initialization started
2012-03-12 13:33:55 [main] INFO org.springframework.web.context.support.XmlWebApplicationContext -
Refreshing Root WebApplicationContext: startup date [Mon Mar 12 13:33:55 CST 2012]; root of context
hierarchy
2012-03-12 13:33:55 [main] DEBUG
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader - Loading bean definitions
2012-03-12 13:33:55 [main] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader -
Loaded 0 bean definitions from location pattern [/WEB-INF/ContextLoaderListener.xml]
2012-03-12 13:33:55 [main] DEBUG org.springframework.web.context.support.XmlWebApplicationContext -
Bean factory for Root WebApplicationContext:
org.springframework.beans.factory.support.DefaultListableBeanFactory@1c05ffd: defining beans []; root
of factory hierarchy
2012-03-12 13:33:55 [main] DEBUG org.springframework.web.context.support.XmlWebApplicationContext -
Bean factory for Root WebApplicationContext:
2012-03-12 13:33:55 [main] DEBUG org.springframework.web.context.ContextLoader - Published root
WebApplicationContext as ServletContext attribute with name
[org.springframework.web.context.WebApplicationContext.ROOT] //将ROOT上下文绑定到ServletContext
2012-03-12 13:33:55 [main] INFO org.springframework.web.context.ContextLoader - Root
WebApplicationContext: initialization completed in 438 ms //到此ROOT上下文启动完毕2012-03-12 13:33:55 [main] DEBUG org.springframework.web.servlet.DispatcherServlet - Initializing
servlet 'chapter2'
信息: Initializing Spring FrameworkServlet 'chapter2'
//开始初始化FrameworkServlet对应的Web上下文
2012-03-12 13:33:55 [main] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet
'chapter2': initialization started
2012-03-12 13:33:55 [main] DEBUG org.springframework.web.servlet.DispatcherServlet - Servlet with name
'chapter2' will try to create custom WebApplicationContext context of class
'org.springframework.web.context.support.XmlWebApplicationContext', using parent context [Root
WebApplicationContext: startup date [Mon Mar 12 13:33:55 CST 2012]; root of context hierarchy]
//此处使用Root WebApplicationContext作为父容器。
2012-03-12 13:33:55 [main] INFO org.springframework.web.context.support.XmlWebApplicationContext -
Refreshing WebApplicationContext for namespace 'chapter2-servlet': startup date [Mon Mar 12 13:33:55
CST 2012]; parent: Root WebApplicationContext
2012-03-12 13:33:55 [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader -
Loading XML bean definitions from ServletContext resource [/WEB-INF/chapter2-servlet.xml]
2012-03-12 13:33:55 [main] DEBUG
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader - Loading bean definitions
2012-03-12 13:33:55 [main] DEBUG org.springframework.beans.factory.xml.BeanDefinitionParserDelegate
- Neither XML 'id' nor 'name' specified - using generated bean name
[org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping#0] //我们配置的HandlerMapping
2012-03-12 13:33:55 [main] DEBUG org.springframework.beans.factory.xml.BeanDefinitionParserDelegate
- Neither XML 'id' nor 'name' specified - using generated bean name
[org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter#0] //我们配置的HandlerAdapter
2012-03-12 13:33:55 [main] DEBUG org.springframework.beans.factory.xml.BeanDefinitionParserDelegate
- Neither XML 'id' nor 'name' specified - using generated bean name
[org.springframework.web.servlet.view.InternalResourceViewResolver#0] //我们配置的ViewResolver
2012-03-12 13:33:55 [main] DEBUG org.springframework.beans.factory.xml.BeanDefinitionParserDelegate
- No XML 'id' specified - using '/hello' as bean name and [] as aliases
//我们的处理器( HelloWorldController )
2012-03-12 13:33:55 [main] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader -
Loaded 4 bean definitions from location pattern [/WEB-INF/chapter2-servlet.xml]
2012-03-12 13:33:55 [main] DEBUG org.springframework.web.context.support.XmlWebApplicationContext -
Bean factory for WebApplicationContext for namespace 'chapter2-servlet':
org.springframework.beans.factory.support.DefaultListableBeanFactory@1372656: defining beans
[org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping#0,org.springframework.web.servl
et.mvc.SimpleControllerHandlerAdapter#0,org.springframework.web.servlet.view.InternalResourceViewR
esolver#0,/hello]; parent:
org.springframework.beans.factory.support.DefaultListableBeanFactory@1c05ffd
//到此容器注册的Bean初始化完毕2012-03-12 13:33:56 [main] DEBUG org.springframework.web.servlet.DispatcherServlet - Unable to locate
MultipartResolver with name 'multipartResolver': no multipart request handling provided
2012-03-12 13:33:56 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory
- Creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
//默认的LocaleResolver注册
2012-03-12 13:33:56 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory
- Creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
//默认的ThemeResolver注册
2012-03-12 13:33:56 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory
- Returning cached instance of singleton bean
'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping#0'
//发现我们定义的HandlerMapping 不再使用默认的HandlerMapping。
2012-03-12 13:33:56 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory
- Returning cached instance of singleton bean
'org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter#0'
//发现我们定义的HandlerAdapter 不再使用默认的HandlerAdapter。
2012-03-12 13:33:56 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory
- Creating instance of bean
'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver'
//异常处理解析器ExceptionResolver
2012-03-12 13:33:56 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory
- Creating instance of bean
'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver'
2012-03-12 13:33:56 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory
- Returning cached instance of singleton bean
'org.springframework.web.servlet.view.InternalResourceViewResolver#0'
2012-03-12 13:33:56 [main] DEBUG org.springframework.web.servlet.DispatcherServlet - Published
WebApplicationContext of servlet 'chapter2' as ServletContext attribute with name
[org.springframework.web.servlet.FrameworkServlet.CONTEXT.chapter2]
//绑定FrameworkServlet初始化的Web上下文到ServletContext
2012-03-12 13:33:56 [main] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet
'chapter2': initialization completed in 297 ms
2012-03-12 13:33:56 [main] DEBUG org.springframework.web.servlet.DispatcherServlet - Servlet
'chapter2' configured successfully
//到此完整流程结束

 

 

 

 

 

 

 




 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值