// 根据类型,创建对应的资源包实例 main = createMainResourceSet();
mainResources.add(main);
// 一次启动此类指定的资源 for (List<WebResourceSet> list : allResources) { // Skip class resources since they are started below if (list != classResources) { for (WebResourceSet webResourceSet : list) { webResourceSet.start(); } } }
// 扫描lib下的所有jar包 processWebInfLib(); // Need to start the newly found resources for (WebResourceSet classResource : classResources) { classResource.start(); }
cache.enforceObjectMaxSizeLimit();
setState(LifecycleState.STARTING); }
}
那我们知道,一个 webapp 入口是 WEB-INF ,因为里边包含了 web.xml 以及 lib包,所以此时就是扫描 lib 下所有的 jar 包,然后加载到 webapp 的 ClassLoader 中去。所以这个时候 StandardRoot 做的事情就是加载所有的 jar 包。
if (!context.getIgnoreAnnotations()) { applicationAnnotationsConfig(); } if (ok) { // 一堆配置鉴权的东西,tomcat-users.xml配置的东西 validateSecurityRoles(); }
if (ok) { authenticatorConfig(); }
if (log.isDebugEnabled()) { log.debug("Pipeline Configuration:"); Pipelinepipeline= context.getPipeline(); Valve valves[] = null; if (pipeline != null) { valves = pipeline.getValves(); } if (valves != null) { for (inti=0; i < valves.length; i++) { log.debug(" " + valves[i].getClass().getName()); } } log.debug("======================"); }
// Make our application available if no problems were encountered if (ok) { context.setConfigured(true); } else { log.error(sm.getString("contextConfig.unavailable")); context.setConfigured(false); } }
if (context.getLogEffectiveWebXml()) { log.info("web.xml:\n" + webXml.toXml()); }
// Step 10. 查找静态资源 if (ok) { // Spec does not define an order. // Use ordered JARs followed by remaining JARs Set<WebXml> resourceJars = newLinkedHashSet<>(); for (WebXml fragment : orderedFragments) { resourceJars.add(fragment); } for (WebXml fragment : fragments.values()) { if (!resourceJars.contains(fragment)) { resourceJars.add(fragment); } } processResourceJARs(resourceJars); }
// Step 11. 应用ServletContainerInitializer配置 if (ok) { for (Map.Entry<ServletContainerInitializer, Set<Class<?>>> entry : initializerClassMap.entrySet()) { if (entry.getValue().isEmpty()) { context.addServletContainerInitializer( entry.getKey(), null); } else { context.addServletContainerInitializer( entry.getKey(), entry.getValue()); } } } }
if (!getUseInheritedChannel()) { // 打开ServerSocketChannel serverSock = ServerSocketChannel.open(); socketProperties.setProperties(serverSock.socket()); InetSocketAddressaddr= (getAddress()!=null?newInetSocketAddress(getAddress(),getPort()):newInetSocketAddress(getPort())); // 绑定端口 serverSock.socket().bind(addr,getAcceptCount()); } else { // Retrieve the channel provided by the OS Channelic= System.inheritedChannel(); if (ic instanceof ServerSocketChannel) { serverSock = (ServerSocketChannel) ic; } if (serverSock == null) { thrownewIllegalArgumentException(sm.getString("endpoint.init.bind.inherited")); } } serverSock.configureBlocking(true); //mimic APR behavior
// 初始化acceptor、poller的线程数 if (acceptorThreadCount == 0) { // FIXME: Doesn't seem to work that well with multiple accept threads acceptorThreadCount = 1; } if (pollerThreadCount <= 0) { //minimum one poller thread pollerThreadCount = 1; } setStopLatch(newCountDownLatch(pollerThreadCount));