javaee标准中,tomcat等web容器启动时走web.xml 先将各种contex-param 放到servletcontxt中变成parameter,然后开始启动容器,容器对外提供了listener可在容器onstartup时做一些操作。

log:

二月 25, 2017 2:56:16 下午 org.apache.catalina.core.ApplicationContext log

信息: No Spring WebApplicationInitializer types detected on classpath

解释:---没找到自定义的spring WebApplicationInitializer

这句日志来自于: org.springframework.web.SpringServletContainerInitializer 在spring-web-x.x.x.Release.jar 包中。

该类实现了servletContainerInitializer 接口的onStartup方法。此接口只有一个方法。这是spring3.1之后的新特性,无web.xml 而是基于代码注解的配置启动servlet。引入了servlet3.0.

* @param c the Set of application classes that extend, implement, or

* have been annotated with the class types specified by the

* {@link javax.servlet.annotation.HandlesTypes HandlesTypes} annotation,

* or <tt>null</tt> if there are no matches, or this

* <tt>ServletContainerInitializer</tt> has not been annotated with

* <tt>HandlesTypes</tt>

c这个param比较有意思,需要实现类增加@HandlesTypes(xx.class)注解。如spring的实现类声明了注解

@HandlesTypes(WebApplicationInitializer.class) 所以spring基于java代码的配置是需要实现WebApplicationInitializer接口的。

@since Servlet 3.0

public interface ServletContainerInitializer {

public void onStartup(Set<Class<?>> c, ServletContext ctx)

throws ServletException;

}

查看此接口的注释

<p>Implementations of this interface must be declared by a JAR file
* resource located inside the <tt>META-INF/services</tt> directory and
* named for the fully qualified class name of this interface, and will be
* discovered using the runtime's service provider lookup mechanism
* or a container specific mechanism that is semantically equivalent to
* it.

大概意思是讲 必须在该接口所在项目的META-INF/services/文件夹下 生成一个文件名字为javax.serlvet.ServletContainerInitializer的文件,内容要与ServletContainerInitializer接口的实现类的全路径一样才能被发现。

仔细看spring-web包下 有类似的结构。声明为了javax.servlet.ServletContainerInitializer的文件,内容为 org.springframework.web.SpringServletContainerInitializer

日志来自于实现类:SpringServletContainerInitializer上一段源码:

 
@Override
public void onStartup(Set<Class<?>> webAppInitializerClasses, ServletContext servletContext)
throws ServletException { List<WebApplicationInitializer> initializers = new LinkedList<WebApplicationInitializer>(); if (webAppInitializerClasses != null) {
for (Class<?> waiClass : webAppInitializerClasses) {
// Be defensive: Some servlet containers provide us with invalid classes,
// no matter what @HandlesTypes says...
if (!waiClass.isInterface() && !Modifier.isAbstract(waiClass.getModifiers()) &&
WebApplicationInitializer.class.isAssignableFrom(waiClass)) {
try {
initializers.add((WebApplicationInitializer) waiClass.newInstance());
}
catch (Throwable ex) {
throw new ServletException("Failed to instantiate WebApplicationInitializer class", ex);
}
}
}
} if (initializers.isEmpty()) {
servletContext.log("No Spring WebApplicationInitializer types detected on classpath");
return;
} AnnotationAwareOrderComparator.sort(initializers);
servletContext.log("Spring WebApplicationInitializers detected on classpath: " + initializers); for (WebApplicationInitializer initializer : initializers) {
initializer.onStartup(servletContext);
}
}

  

因为没有使用基于servlet3.0规范的类,所以有这一条日志。

 

log:

Initializing Spring root WebApplicationContext

解释:日志是由类

WebApplicationContextorg.springframework.web.context.ContextLoader.initWebApplicationContext(ServletContext servletContext)打印的,contextLoader作为ContextLoaderListener的private 变量。标识着启动wac。核心代码在wac.refresh()中。

值得注意的是注册核心类之前,会先处理beanFactory的PostProcesors类。

这些类一般都实现了 

BeanFactoryPostProcessor 这个接口。通常讲抽象类PropertyResourceConfigurer比较重要。

org.springframework.beans.factory.config.PropertyResourceConfigurer

源码注释:
/* Allows for custom modification of an application context's bean definitions,
* adapting the bean property values of the context's underlying bean factory.
*
* <p>Application contexts can auto-detect BeanFactoryPostProcessor beans in
* their bean definitions and apply them before any other beans get created.
*
* <p>Useful for custom config files targeted at system administrators that
* override bean properties configured in the application context.

*/

LOG:

2017-02-25 19:29:08:719  INFO  [mvc.annotation.DefaultAnnotationHandlerMapping] Mapped URL path

解释:

启动wac时,会由读取@RequestMapping 注解拼接url ,并缓存 {url,method}的映射关系。

LOG:

二月 25, 2017 7:40:29 下午 org.apache.catalina.core.ApplicationContext log

信息: Initializing Spring FrameworkServlet 'led'

2017-02-25 19:40:29:584  INFO  [web.servlet.DispatcherServlet] FrameworkServlet 'led': initialization started

2017-02-25 19:40:29:603  INFO  [context.support.XmlWebApplicationContext] Refreshing WebApplicationContext for namespace 'led-servlet': startup date [Sat Feb 25 19:40:29 CST 2017]; parent: Root WebApplicationContext

2017-02-25 19:40:29:605  INFO  [factory.xml.XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/led-servlet.xml]

解释:开始启动servlet,配置为DispatcherServlet 并执行父类 FrameworkServlet 的父类 HttpServletBean的init方法,并钩子调用FrameworkServlet的initServletBean()创建servlet容器 放到servletContext

setAttribute(Framework.class.getName()+".CONTEXT"+ServletName,WAC);并且将WAC的parent设置为ContextLoaderListener创建的WAC。

至此SpringMVC启动完毕。

更加详细的内容下一篇随笔。





从springmvc启动日志学习的更多相关文章

  1. Spring+SpringMVC+MyBatis深入学习及搭建(十二)——SpringMVC入门程序(一)

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6999743.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十一)——S ...

  2. Spring+SpringMVC+MyBatis深入学习及搭建(十二)——SpringMVC入门程序

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6999743.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十一)--S ...

  3. Spring+SpringMVC+MyBatis深入学习及搭建(十四)——SpringMVC和MyBatis整合

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/7010363.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十三)--S ...

  4. Spring+SpringMVC+MyBatis深入学习及搭建(十七)——SpringMVC拦截器

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/7098753.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十六)--S ...

  5. Java 日志学习

    Java 日志学习,主要学习log4j,(为了查找方便,直接拷贝别人文章:原文:http://www.cnblogs.com/xt0810/p/3659045.html) [结构] java日志对调试 ...

  6. Log4j,Log4j2,logback,slf4j日志学习

    日志学习笔记 Log4j Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.数据库等:我们也可以控制每一条日志的输出格式:通过定义每一条 ...

  7. Log4j,Log4j2,logback,slf4j日志学习(转)

    日志学习笔记Log4jLog4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.数据库等:我们也可以控制每一条日志的输出格式:通过定义每一条日志 ...

  8. Spring Boot 2.x基础教程:找回启动日志中的请求路径列表

    如果您看过之前的Spring Boot 1.x教程,或者自己原本就对Spring Boot有一些经验,或者对Spring MVC很熟悉.那么对于Spring构建的Web应用在启动的时候,都会输出当前应 ...

  9. SpringMVC启动过程详解(li)

    通过对SpringMVC启动过程的深入研究,期望掌握Java Web容器启动过程:掌握SpringMVC启动过程:了解SpringMVC的配置文件如何配置,为什么要这样配置:掌握SpringMVC是如 ...

随机推荐

  1. MySQL的查询,子查询,联结查询,联合查询

    MySQL的查询,子查询,联结查询,联合查询 一.mysql查询的五种子句where(条件查询).having(筛选).group by(分组).order by(排序).limit(限制结果数) 二 ...

  2. Python魔法师

    第一章:数据结构和算法 1.1 查找最大或者最小的n个元素 heapq 模块的两个函数 nlargest()  nsmallest() import heapq nums = [1, 8, 2, 23 ...

  3. Ros 中的多线程

      参考文献:http://blog.csdn.net/sinat_27554409/article/details/48446611 老王说ROS http://blog.csdn.net/yake ...

  4. .aspx 页面引用命名空间

    一.单个页面引用: <%@ Import Namespace="" %> 二.所有页面引用,Web.config配置如下: <system.web> < ...

  5. 初探boost之smart_ptr库学习笔记

    概述 Boost.smart_ptr库提供了六种智能指针,除了shared_ptr 和 weak_ptr 以外还包含 scoped_ptr .scoped_array . shared_array . ...

  6. ubuntu 安装时出错 sudo apt-get update Reading package lists… Error

    安装过程出错 首先出现问题sudo apt-get updateReading package lists… Error!E: Encountered a section with no Packag ...

  7. linux svn 更新地址

    进行你所工作的svn映射到本地的目录中.在终端下运行$svn switch --relocate http://oldPath http://newpath.系统提示输入用户名,密码.重新输入后,即可 ...

  8. Redis源码阅读-Dict哈希字典

    Dict和Java中的HashMap很相似,都是数组开链法解决冲突. 但是Redis为了高性能, 有很多比较微妙的方法,例如 数组的大小总是2的倍数,初始大小是4. rehash并不是一次就执行完,而 ...

  9. Apache中KeepAlive 配置

    引子 先来分析一个Yslow 测试的一个页面的前端性能. 这里所有的请求是指http请求,对于一个请求各个阶段的划分,阻挡->域名解析->建立连接->发送请求->等待响应-&g ...

  10. win10正式版开始菜单无法打开,右边的网络连接、操作中心也打不开

    问题描述: 开机后电脑键盘的win键无响应,鼠标点击菜单栏中的这几个按键也都无响应,但是点击自己固定的应用程序却没有问题,在网上查找尝试了许多资料,终于找到了一个合适的解决方案.现记录如下 解决方案: ...