Jetty在启动时,先启动Server,调用jettyserver的父类 HandlerWrapper的dostart方法,启动handler,handler是一个HandlerWrapper,总共包含8个Handler,循环调用Handler的start方法,启动各个Handler。
其中XX,负责解析webapp的基本信息,解析web.xml,并将信息保存到实体中。然后调用WebAppContext 的doStart 启动, 记载和调用在web.xml中解析并已经加载的所有Listener的contextInitialized 方法,启动listener。
本文分析的主要包括:webapp的解析和启动、请求的处理、权限的管理、jsp的解析。
(一)webapp的解析和启动包括:
- webapp的解析和启动
- Spring的启动和Bean的加载等
(二)请求的处理包括:
- jetty如何处理请求,并转发到spring
- spring如何处理请求
(三)权限的管理包括:
- jetty如何管理cookies和session
- spring security如何管理权限
(四)jsp的解析
- jsp如何转化为servlet
- 各个模板引擎是如何工作的
一、webapp的解析和启动
服务启动时调用server的dostart方法,dostart方法调用父类HandlerWrapper的dostart方法,dostart方法启动Handler的,这个Handler是一个HandlerCollection,包含三个元素,循环启动三个Handler。
- 0 = {ContextHandlerCollection@3593}
- 1 = {DefaultHandler@3633}
- 2 = {RequestLogHandler@3634}
其中ContextHandlerCollection是部署的app,webapp目录下面有多少个war,就有多少个JettyWebAppContext元素,循环调用JettyWebAppContext的start方法启动app的部署和解析。
1、web.xml的解析
JettyWebAppContext 的类层次结构如下:
JettyWebAppContext > WebAppContext > ServletContextHandler > ContextHandler > ScopeHandler > HandlerWrapper > AbstractHandlerContainer > AbstractHandler > AggregateLifeCycle > AbstractLifeCycle
protected void doStart() throws Exception { try { this._metadata.setAllowDuplicateFragmentNames(this.isAllowDuplicateFragmentNames()); this.preConfigure(); super.doStart(); this.postConfigure(); if(this.isLogUrlOnStart()) { this.dumpUrl(); } } catch (Exception var2) { LOG.warn("Failed startup of context " + this, var2); this._unavailableException = var2; this.setAvailable(false); if(this.isThrowUnavailableOnStartupException()) { throw var2; } } }
dostart方法的调用堆栈如下:
at org.eclipse.jetty.webapp.StandardDescriptorProcessor.visitSessionConfig(StandardDescriptorProcessor.java:667) at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.visit(IterativeDescriptorProcessor.java:85) at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.process(IterativeDescriptorProcessor.java:72) at org.eclipse.jetty.webapp.MetaData.resolve(MetaData.java:366) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1240) ContextHandler的startContext方法 at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494) at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:298)
其中_configurations 包含如下:
0 = {MavenWebInfConfiguration@3811}
1 = {WebXmlConfiguration@3812}
2 = {MetaInfConfiguration@3813}
3 = {FragmentConfiguration@3814}
4 = {EnvConfiguration@3675}
5 = {PlusConfiguration@3815}
6 = {MavenAnnotationConfiguration@3816}
7 = {JettyWebXmlConfiguration@3817}
MavenWebInfConfiguration主要处理webinf目录和一些临时目录等相关的配置。
WebXmlConfiguration负责定位和解析web.xml配置文件。
MetaInfConfiguration负责解析jar包。
org.eclipse.jetty.webapp.WebAppContext.startContext最后负责启动所有的Listener,如果使用了Spring框架,此时会启动Spring的ContextLoaderListener。
0 = {ELContextCleaner@5759}
1 = {IntrospectorCleaner@5760}
2 = {LogbackConfigListener@5761}
3 = {SystemLoaderListener@5762}
4 = {OnlineInfoListener@5763}
在WebAppContext的启动过程中启动了SessionHandler。
at org.eclipse.jetty.server.session.HashSessionManager.doStart(HashSessionManager.java:92) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) - locked <0x12c1> (a java.lang.Object) at org.eclipse.jetty.server.session.SessionHandler.doStart(SessionHandler.java:123) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) - locked <0x1287> (a java.lang.Object) at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95) at org.eclipse.jetty.server.handler.ScopedHandler.doStart(ScopedHandler.java:115) at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
2、Spring的启动
第一步解析并把bean的定义加载到集合中,此时不会初始化bean,因为bean可能存在以来关系。
第二步分析bean的依赖关系.
第三步创建并加载bean
bean的解析和加载是一个递归的过程。
如果是XML的context配置,通过web.xml配置文件找到Spring的初始配置文件,并解析。包括外部文件、component-scan、bean的创建、资源的映射等的处理。
其中parseDefaultElement方法根据不同的类型进行不同的处理。
相关推荐
通过整合SpringMVC+SpringBoot+Mybatis构建一个可用的基于SpringCloud的微服务工程将上述技术组件逐步落地,让大家看得懂做得出学得会。 00、硅谷学习_SpringBoot_源码、课件 01.硅谷学习_SpringCloud_前提概述 ...
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2317365
spring security 项目配置源码,项目是在eclipse启动的jdk1.8 tomcat1.8能正常运行,有助于学习.zip
可用于分析spring mvc源码、spring mvc父子容器初始化流程、session和cookie机制、spring session等,也可以用于学习Java Web(servlet、filter、listener等)、spring源码等。 该项目使用servlet3.0规范,无web.xml...
Tcp服务端与客户端的JAVA实例源代码,一个简单的Java TCP服务器端程序,别外还有一个客户端的程序,两者互相配合可以开发出超多的网络程序,这是最基础的部分。 递归遍历矩阵 1个目标文件,简单! 多人聊天室 3...
项目能够完美运行,如有不明白请参考博文http://blog.csdn.net/zhshulin/article/details/37956105 进行学习
通过源码分析主要给大家介绍了关于Spring启动时Context加载的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目...
内容概要:该资源是Spring全家桶视频课程的第三部分Spring Boot的源码,其对于Spring Boot的最常用的第一个小程序、JavaConfig和常见注解、启动改变、热部署、Springboot整合Thymeleaf/freemarker/JSP、异常处理、...
SpringCloud微服务课程说明 1 网站架构演变过程 1 传统架构 1 分布式架构 1 SOA架构 1 微服务架构 2 微服务架构产生的原因 2 漫谈微服务架构 2 什么是微服务 2 微服务架构特征 3 微服务架构如何拆分 3 ...
基于springcloud和vue微服务,前后端分离的后台管理框架,可以作为springcloud和vue的入门学习框架,亦可以作为一个基础脚手架进行二次开发 使用说明 1.新建数据库,导数数据库脚本(clouddo-admin的根目录下),...
主要给大家介绍了关于Spring启动流程refresh()源码深入解析的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
错过了这一篇,你可能再也学不会 Spring Cloud 了!Spring Boot做为下一代 web 框架,Spring Cloud 作为最新最火的微服务的翘楚,你还有什么理由拒绝。赶快上船吧,老船长带你飞。终章不是最后一篇,它是一个汇总,...
spring 一、配置阶段 1、web.xml DispatcherServlet 由Spring提供的 2、init-param classpath:application.xml contextConfigLoation 3、url-pattern /* 二、初始化、启动阶段 1、init 加载spring的配置文件 2、IOC...
学成在线就是一个在线学习平台,类似慕课网以及腾讯学堂,是专门针对IT行业进行在线学习的平台。 学成在线采用B2B2C的业务模式,即向企业与个人提供平台实现教学服务,其中企业就是老师,提供课程,作业,考试等;...
Spring boot开启定时任务的三种方式 零、前言 第一种也就是最简单的一种:基于注解 (@Scheduled)的方式; 第二种:基于接口 (SchedulingConfigurer); 第三种:基于注解设定多线程定时任务。 一、基于@Scheduled注解...
主要给大家介绍了关于SPRING BOOT启动命令参数及源码分析的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用SPRING BOOT具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
使用 Spring Boot 一键式启动。 下载项目,运行c2c.sql文件,然后运行 UsedTradingPlatformApplication.main 方法即可启动。 环境 jdk1.8 mysql5.7 先在数据中创建名为c2c的数据库,使用Navicat for MySQL运行 ...
本课程中使用的所有源代码示例都是使用最新版本的Spring Framework开发的-Spring Framework 5和Spring Boot 2。您将使用Spring Framework 5构建多个真实世界的应用程序。您将利用Spring Boot 2的功能,了解现代...