tomcat-2-启动和初始化

概述

  • Tomcat核组件
    • Connector:底层通信
    • Container:Servlet业务
      • 4个级别:Engine,Host,Context,Wrapper(Servlet)

Windows

  • 双击startup.bat启动(意味着不带参数)
    • CATALINA_HOME未定义,确定CATALINA_HOME
      • 从当前位置往外找,直到%CATALINA_HOME%\bin\catalina.bat存在
    • %CATALINA_HOME%\bin\catalina.bat start
  • catalina.bat
start Tomcat "%JAVA_HOME%\bin\java.exe"
  -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
  -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
  "-Djdk.tls.ephemeralDHKeySize=2048"
  -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
  -Dignore.endorsed.dirs=""
  -classpath "%CATALINA_HOME%\bin\bootstrap.jar;D:\apache-tomcat-9.0.2\bin\tomcat-juli.jar"
  -Dcatalina.base="%CATALINA_BASE%"
  -Dcatalina.home="%CATALINA_HOME%"
  -Djava.io.tmpdir="%CATALINA_BASE%\temp"
  org.apache.catalina.startup.Bootstrap start

Bootstrap

  • static代码块
    • catalinaHomeFile,catalinaBaseFile赋值
  • main方法
    • Bootstrap bootstrap = new Bootstrap();
    • init
      • initClassLoaders
        • commonLoader,catalinaLoader,sharedLoader
      • 用catalinaLoader加载Catalina
        • Class startupClass = catalinaLoader.loadClass("org.apache.catalina.startup.Catalina");
        • Object startupInstance = startupClass.getConstructor().newInstance();
      • 设置Catalina的parentClassLoader属性为sharedLoader
      • catalinaDaemon = startupInstance
    • daemon = bootstrap
    • daemon.setAwait(true):设置catalinaDaemon的await属性
    • daemon.load(args):调catalinaDaemon的load
    • daemon.start():调catalinaDaemon的start

你可能感兴趣的:(tomcat-2-启动和初始化)