Tomcat启动流程之StandardContext启动
2020-04-03 07:42
1126 查看
StandardContext启动
对一些启动过程进行详细分析一下这个分析不是完整的完整的请看我的收藏这里只是对一些不清楚的地方补充了一下
protected void deployApps() { File appBase = host.getAppBaseFile(); File configBase = host.getConfigBaseFile(); // 过滤出 webapp 要部署应用的目录 String[] filteredAppPaths = filterAppPaths(appBase.list()); // 部署 xml 描述文件 deployDescriptors(configBase, configBase.list()); // 解压 war 包,但是这里还不会去启动应用 //StandardContext的启动入口 //看其他文章找了好久 deployWARs(appBase, filteredAppPaths); // 处理已经存在的目录,前面解压的 war 包不会再行处理 deployDirectories(appBase, filteredAppPaths); }
代码有点长我也贴出来了 具体分析我就不解释了可以看注释
protected void deployWARs(File appBase, String[] files) { if (files == null) return; ExecutorService es = host.getStartStopExecutor(); List<Future<?>> results = new ArrayList<>(); for (int i = 0; i < files.length; i++) { if (files[i].equalsIgnoreCase("META-INF")) continue; if (files[i].equalsIgnoreCase("WEB-INF")) continue; File war = new File(appBase, files[i]); if (files[i].toLowerCase(Locale.ENGLISH).endsWith(".war") && war.isFile() && !invalidWars.contains(files[i]) ) { ContextName cn = new ContextName(files[i], true); if (isServiced(cn.getName())) { continue; } if (deploymentExists(cn.getName())) { DeployedApplication app = deployed.get(cn.getName()); boolean unpackWAR = unpackWARs; if (unpackWAR && host.findChild(cn.getName()) instanceof StandardContext) { unpackWAR = ((StandardContext) host.findChild(cn.getName())).getUnpackWAR(); } if (!unpackWAR && app != null) { // Need to check for a directory that should not be // there File dir = new File(appBase, cn.getBaseName()); if (dir.exists()) { if (!app.loggedDirWarning) { log.warn(sm.getString( "hostConfig.deployWar.hiddenDir", dir.getAbsoluteFile(), war.getAbsoluteFile())); app.loggedDirWarning = true; } } else { app.loggedDirWarning = false; } } continue; } // Check for WARs with /../ /./ or similar sequences in the name if (!validateContextPath(appBase, cn.getBaseName())) { log.error(sm.getString( "hostConfig.illegalWarName", files[i])); invalidWars.add(files[i]); continue; } // 进入DeployWar方法这个方法太长了 results.add(es.submit(new DeployWar(this, cn, war))); } }
Class<?> clazz = Class.forName(host.getConfigClass()); LifecycleListener listener = (LifecycleListener) clazz.getConstructor().newInstance(); context.addLifecycleListener(listener); context.setName(cn.getName()); context.setPath(cn.getPath()); context.setWebappVersion(cn.getVersion()); context.setDocBase(cn.getBaseName() + ".war"); //从这进去 host.addChild(context);
@Override public void addChild(Container child) { if (!(child instanceof Context)) throw new IllegalArgumentException (sm.getString("standardHost.notContext")); child.addLifecycleListener(new MemoryLeakTrackingListener()); // Avoid NPE for case where Context is defined in server.xml with only a // docBase Context context = (Context) child; if (context.getPath() == null) { ContextName cn = new ContextName(context.getDocBase(), true); context.setPath(cn.getPath()); } //调用父类ContainerBase super.addChild(child); }
@Override public void addChild(Container child) { if (Globals.IS_SECURITY_ENABLED) { PrivilegedAction<Void> dp = new PrivilegedAddChild(child); AccessController.doPrivileged(dp); } else { //继续进去 addChildInternal(child); } }
private void addChildInternal(Container child) { if( log.isDebugEnabled() ) log.debug("Add child " + child + " " + this); synchronized(children) { if (children.get(child.getName()) != null) throw new IllegalArgumentException("addChild: Child name '" + child.getName() + "' is not unique"); child.setParent(this); // May throw IAE children.put(child.getName(), child); } // Start child // Don't do this inside sync block - start can be a slow process and // locking the children object can cause problems elsewhere try { if ((getState().isAvailable() || LifecycleState.STARTING_PREP.equals(getState())) && startChildren) { //这里开始启动StandardContext child.start(); } } catch (LifecycleException e) { log.error("ContainerBase.addChild: start: ", e); throw new IllegalStateException("ContainerBase.addChild: start: " + e); } finally { fireContainerEvent(ADD_CHILD_EVENT, child); } }
到这里只是进入到了StandardContext下面的步骤就看我的收藏吧
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 在Mac上关于tomcat服务器的安装、配置、启动、部署web详细流程
- Mac上关于tomcat服务器的安装、配置、启动、部署web详细流程
- Spring Boot启动过程(六):内嵌Tomcat中StandardHost、StandardContext和StandardWrapper的启动
- Tomcat源码阅读之Server.xml文件的处理与Catalina启动流程
- 在Mac上关于tomcat服务器的安装、配置、启动、部署web详细流程
- Tomcat源码解析(五):Connector连接器的初始化和启动流程
- (笔记)struts2流程1 -- Tomcat启动时
- 在Mac上关于tomcat服务器的安装、配置、启动、部署web详细流程
- 使用eclipse部署项目时Tomcat一旦添加项目启动就报错-》StandardEngine[Catalina].StandardHost[localhost].StandardContext[/
- Tomcat 8/7 无法启动 [StandardEngine[Catalina].StandardHost[localhost].StandardContext
- Tomcat源码阅读之Server.xml文件的处理与Catalina启动流程
- tomcat启动流程日志
- Tomcat8源码笔记(九)组件StandardContext启动流程--未完待续
- Tomcat学习 HttpConnector和HttpProcessor启动流程和线程交互
- tomcat-tomcat启动流程
- 理解Tomcat架构、启动流程及其性能优化
- SpringBoot:深入探索内嵌tomcat启动流程
- 理解Tomcat架构、启动流程及其性能优化
- Tomcat源码分析之—具体启动流程分析
- Tomcat 启动流程