java web.xml中加载顺序

web.xml中加载顺序是context-param -> listener -> filter -> servlet并不因在web.xml中配置顺序而改变


以自己的项目tdsTest为例
1.
首先读取web.xml中设置,根据<context-param> namecontextConfigLocation取相应的值,如

 <param-value>classpath:application.xml</param-value>

2.获取application.xml相应的设置,像这个project,就有import一个spring-mybatis.xml设置,然后初始化数据库相关配置

3. spring-mybatis.xml配置了数据库连接,mybatis印射的相关信息,从哪个地方去找mappermapper.xml,事务日志管理等

4.然后init DispatcherServlet,这里配置spring-mvc.xml servlet相关信息,比如自动扫描Controller,ServiceImpl,静态资源等

项目结构:

图片显示结构:



CallStack:

2017-07-19 19:11:30 [RMI TCP Connection(3)-127.0.0.1] INFO  org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
2017-07-19 19:11:30 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Wed Jul 19 19:11:30 CST 2017]; root of context hierarchy
2017-07-19 19:11:30 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [application.xml]
2017-07-19 19:11:30 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring/spring-mybatis.xml]
2017-07-19 19:11:30 [RMI TCP Connection(3)-127.0.0.1] INFO  com.alibaba.druid.pool.DruidDataSource - {dataSource-1} inited
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 913 ms
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcher': initialization started
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Wed Jul 19 19:11:31 CST 2017]; parent: Root WebApplicationContext
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring/spring-mvc.xml]
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/info/getCatJobInfo],methods=[GET]}" onto public java.util.List<com.ekin.test.bean.CatJobInfo> com.ekin.test.controller.CatJobInfoController.getCatJobInfo()
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Wed Jul 19 19:11:31 CST 2017]; parent: Root WebApplicationContext
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Wed Jul 19 19:11:31 CST 2017]; parent: Root WebApplicationContext
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/common/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/css/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#1'
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/image/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#2'
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/js/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#3'
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/info/getCatJobInfo],methods=[GET]}" onto public java.util.List<com.ekin.test.bean.CatJobInfo> com.ekin.test.controller.CatJobInfoController.getCatJobInfo()
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Wed Jul 19 19:11:31 CST 2017]; parent: Root WebApplicationContext
2017-07-19 19:11:31 [RMI TCP Connection(3)-127.0.0.1] INFO  org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcher': initialization completed in 628 ms
2017-07-19 19:13:35 [http-apr-8080-exec-1] INFO  com.ekin.test.controller.CatJobInfoController - [com.ekin.test.bean.CatJobInfo@1e7aff31, com.ekin.test.bean.CatJobInfo@1d07f999]


猜你喜欢

转载自blog.csdn.net/kielin/article/details/75879097