Tomcat配置文件与启动顺序

  三个配置应用的位置:

  1、conf目录下的server.xml文件:此方式为Eclipse默认配置方法,同时也是三种方式中优先级最高的。

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--><!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 --><Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->

    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector connectionTimeout="20000" port="8081" protocol="HTTP/1.1" redirectPort="8443"/>
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine defaultHost="localhost" name="Catalina">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>

      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>

      <Context docBase="spring-websocket-portfolio" path="/spring-websocket-portfolio" reloadable="true" source="org.eclipse.jst.jee.server:spring-websocket-portfolio"/></Host>
    </Engine>
  </Service>
</Server>

多个应用时只需在最后的<Context>标签多写几个即可。docBase为发布目录,Eclipse默认为.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps下,前提为该应用时Eclipse通过tomcat启动的。因为Eclipse里配置了tomcat的启动参数

-Dcatalina.base="G:\Web\JSP\Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0" -Dcatalina.home="C:\Program Files\Apache Software Foundation\Tomcat 8.0" -Dwtp.deploy="G:\Web\JSP\Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps" -Djava.endorsed.dirs="C:\Program Files\Apache Software Foundation\Tomcat 8.0\endorsed"

2、conf\Catalina\localhost目录下配置一个--目录名.xml文件,文件内容为

<Context docBase="test" path="/test" reloadable="true" />

这个path要和文件名一致,docBase为应用目录,默认在webapps目录下。

启动顺序比1低。

3、直接部署在默认的webapps目录下,tomcat会自动部署该项目。优先级最低。

扫描启动时在org.apache.catalina.startup.HostConfig类中的start()方法中,调用的

deployApps() 方法

 protected void deployApps() {

        File appBase = host.getAppBaseFile();
        File configBase = host.getConfigBaseFile();
        String[] filteredAppPaths = filterAppPaths(appBase.list());
        // Deploy XML descriptors from configBase
        deployDescriptors(configBase, configBase.list());
        // Deploy WARs
        deployWARs(appBase, filteredAppPaths);
        // Deploy expanded folders
        deployDirectories(appBase, filteredAppPaths);

    }

其中,appBase为配置的默认部署目录,默认情况下为webapps目录

configBase为conf/Catalina/localhost目录,deployDescriptors方法:

/**
     * Deploy XML context descriptors.
     */
    protected void deployDescriptors(File configBase, String[] files) {

        if (files == null)
            return;

        ExecutorService es = host.getStartStopExecutor();
        List<Future<?>> results = new ArrayList<>();

        for (int i = 0; i < files.length; i++) {
            File contextXml = new File(configBase, files[i]);

            if (files[i].toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
                ContextName cn = new ContextName(files[i], true);

                if (isServiced(cn.getName()) || deploymentExists(cn.getName()))
                    continue;

                results.add(
                        es.submit(new DeployDescriptor(this, cn, contextXml)));
            }
        }

        for (Future<?> result : results) {
            try {
                result.get();
            } catch (Exception e) {
                log.error(sm.getString(
                        "hostConfig.deployDescriptor.threaded.error"), e);
            }
        }
    }

取该文件夹下的所有xml文件,并取部署目录下同名文件夹,进行部署。最后才是部署默认目录的war包。

上图为Eclipse下tomcat的配置,General Information为通用信息,Runtime Environment可配置Java的环境等,OpenLaunchConfiguration为配置启动参数等,Configuration即tomcat的conf目录。

server locations为服务器文件放在何处,即配置文件,部署目录等放在哪里,只有移除全部module这里才可以做修改。

server options为服务器选项。第一个是不发布,即不放到target目录(?)。第二个为为每个应用发布到单独的xml文件,即localhost目录下。

第三个是默认重载模块,即做修改便重载。后略。

发布的一些选项,是否修改文件等等。超时选项,端口设置等等。

ps:配置session超时时间为:

1、修改server.xml下的应用配置:

<Context path="/test" docBase="/test"
  defaultSessionTimeOut="3600" isWARExpanded="true"
  isWARValidated="false" isInvokerEnabled="true"
  isWorkDirPersistent="false"/>

2、web.xml下

  <session-config>
  <session-timeout>20</session-timeout>
  </session-config>

3、

在程序中定义:
  session.setMaxInactiveInterval(30*60);
  设置单位为秒,设置为-1永不过期
  不知道这种设置会不会真正地起到作用的哦!

session.setTimeout(你设置的时间);   ------>>> 这个也可以,但是和setMaxInactiveInterval有什么差别暂时没有体会。

时间: 2024-08-10 17:17:31

Tomcat配置文件与启动顺序的相关文章

使用spring等框架的web程序在Tomcat下的启动顺序及思路理清

大牛请绕过,此文仅针对自己小白水平,对web程序的启动流程做个清晰的回顾. 一.使用spring等框架的web程序在Tomcat下的启动流程 1)Tomcat是根据web.xml来启动的.首先到web.xml 2)web.xml中负责启动spring和spring mvc.对应的启动配置文件分别是 启动spring mvc,并进行所有资源路径映射 <servlet> <servlet-name>springMVC</servlet-name> <servlet-c

详解Tomcat 配置文件server.xml

前言 Tomcat隶属于Apache基金会,是开源的轻量级Web应用服务器,使用非常广泛.server.xml是Tomcat中最重要的配置文件,server.xml的每一个元素都对应了Tomcat中的一个组件:通过对xml文件中元素的配置,可以实现对Tomcat中各个组件的控制.因此,学习server.xml文件的配置,对于了解和使用Tomcat至关重要. 本文将通过实例,介绍server.xml中各个组件的配置,并详细说明Tomcat各个核心组件的作用以及各个组件之间的相互关系. 说明:由于s

修改grub启动顺序

1. 其实就是修改/boot/grub/grub.cfg这个文件,从后缀就看得出这是一个配置文件,虽然linux不区分这后缀,这个后缀是个用户看的. 2. 看了下这个文件,其实我也不理解里面的全部东西,能够理解他的一些语法,但是没能理解他的本意,不过看到后面我既然发现menuentry的顺序就是开机的启动顺序,于是我把这个顺序修改了一下就好了.这样之后就是win7作为第一启动项了,之前我们看到的情况应该是"Ubuntu"在最前面,然后window7在最后面,这样修改后就ok,里面还有背

修改Fedora 25与Windows 10的默认启动顺序

首先贴出Fedora25下/boot/grub2/grub.cfg的内容: 1 # 2 # DO NOT EDIT THIS FILE 3 # 4 # It is automatically generated by grub2-mkconfig using templates 5 # from /etc/grub.d and settings from /etc/default/grub 6 # 7 8 ### BEGIN /etc/grub.d/00_header ### 9 set pag

Tomcat是如何启动及运行—对tomcat的源码解析

本文是我阅读了Tomcat源码后的一些心得.主要是讲解Tomcat的系统框架,启动流程已经运行过程.若有错漏之处,敬请批评指教. 先给出几个问题: tomcat作为一个应用服务器的程序入口在哪里? tomcat的整体组件结构是什么样的? tomcat是什么时候及如何创建线程来处理请求的? tomcat的配置文件context.xml,server.xml,tomcat-users.xml,web.xml什么时候加载的及作用是什么? 最后,tomcat是如何启动运行的? 我通过源码来分析这些问题.

ubuntu更改启动顺序

在ubuntu中修改启动配置. 启动相关grub2主要包含下面三个文件:1.   /boot/grub/grub.cfg 文件    2.   /etc/grub.d/ 文件夹   3.   /etc/default/grub 文件,可以通过修改这三个文件来修改启动项 链接:http://blog.csdn.net/zhu_liangwei/article/details/7847034 一 更改启动顺序,验证过的两种方式 1.修改 /etc/default/grub 文件 打开文件 sudo

Linux开机启动顺序简述

Linux的开机启动顺序 第一步:当然是加电了 第二步:加载BIOS设置,选择启动盘.这是因为因为BIOS中包含了CPU的相关信息.设备启动顺序信息.硬盘信息.内存信息.时钟信息.PnP特性等等.在此之后,计算机心里就有谱了,知道应该去读取哪个硬件设备了.在BIOS将系统的控制权交给启动硬盘第一个扇区之后,就开始由Linux来控制系统了. 第三步:加载磁盘中MBR中的grub MBR(Master Boot Record):即主引导分区,是启动盘的前512字节,里面存放了预启动信息和分区信息.前

第一章之s5pv210启动顺序

我所使用的开发板是:友善之臂smart210,cpu为s5pv210.u-boot版本是:u-boot-2012-10 1,首先在u-boot中配置相对应的开发板的配置文件 #make s5p_goni_config 2,设事先编译好的交叉编译器放在Makefile中添加上去,打开Makefile 在67行补充CROSS_COMPILE ?= arm-linux- 3,通过s5pv210启动顺序可以看出,启动由两个过程来进行boot,分别称为BL1,BL2. (1)BL0:是指S5PV210的i

Tomcat5的web应用启动顺序详解

Tomcat5的web应用启动顺序详解 [收藏此页] [打印] 作者:佚名  2007-07-17 内容导航: 第1页 [IT168技术文档]摘要: 应用Tomcat对于我们来讲实在是司空见惯了,但是对于每个使用者来讲,应该了解其运转的机制也是必不可少的,本人在维护"apache开源项目"论坛时遇到此问题,并略作研究,望与大家共讨.分享. 一.配置自动部署时的web应用加载顺序: 当tomcat的server.xml中对虚拟主机(Host)配置中autoDeploy=true和unpa