首页 > 其他分享 >Tomcat 配置文件笔记

Tomcat 配置文件笔记

时间:2022-12-09 17:05:21浏览次数:52  
标签:xml 配置文件 Tomcat 笔记 xzg conf mysql type name

Tomcat 配置文件笔记
tomcat 版本: 5.5.20
服务器主配置文件路径: {installDir}/conf/server.xml 。
服务器上下文配置文件路径: {installDir}/conf/context.xml 。

如:
D:/WAS/apache-tomcat-5.5.20/conf/server.xml
D:/WAS/apache-tomcat-5.5.20/conf/context.xml
D:/WAS/apache-tomcat-5.5.20/conf/tomcat-users.xml
D:/WAS/apache-tomcat-5.5.20/conf/web.xml

1. 配置方式一:​

在 conf/server.xml 配置文件中配置 <Rescource> 和 <RescourceLink> 方式。

<?xml version="1.0" encoding="UTF-8"?>
<Server
port="8006"
shutdown="111">
<Listener className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
<Resource
name="xzg/orcl10gr2"
type="javax.sql.DataSource"
password="tiger"
driverClassName="oracle.jdbc.OracleDriver"
maxIdle="2"
maxWait="5000"
username="scott"
url="jdbc:oracle:thin:@xizhiguang:1521:orcl"
maxActive="20"/>
<Resource
name="xzg/mysql"
type="javax.sql.DataSource"
password="javaduke"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="javauser"
url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"
maxActive="20"/>
</GlobalNamingResources>
​​[x1]​​ <Service
name="Catalina">
<Connector
port="8080"
redirectPort="8443"
minSpareThreads="25"
connectionTimeout="20000"
uRIEncoding="GBK"
maxSpareThreads="75"
maxThreads="150">
</Connector>
<Connector
port="8009"
redirectPort="8443"
protocol="AJP/1.3">
</Connector>
<Engine
defaultHost="localhost"
name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
<Host
appBase="webapps"
name="localhost">
<Context
docBase="DBTest"
crossContext="true"
path="/DBTest"
privileged="true"
reloadable="true">
<ResourceLink
global="xzg/orcl10gr2"
auth="Container"
type="javax.sql.DataSource"
name="xzg/orcl10gr2"/>
<ResourceLink
global="xzg/mysql"
auth="Container"
type="javax.sql.DataSource"
name="xzg/mysql"/>​​[x2]​​ <WatchedResource>D:/was/apache-tomcat-5.5.20/conf/context.xml</WatchedResource>
</Context>
</Host>
</Engine>
</Service>
</Server>


在 <Host></Host> 标记内加上下文标记 <Context></Context> ,在 <Context></Context> 内加 <Resource></Resource> 或者 <ResourceLink></ResourceLink>标记,来定义数据源配置。


注意:​
通过实际观察发现Tomcat 服务器启动和停止的时候都会校验 conf/server.xml 文件。
如,在运行过程中,修改了 server.xml 配置文件,填入了错误信息,停止服务器的时候就会导致服务器抛出异常停不下来服务器,修改正确后方可停止。 配置文件的错误会导致服务器启动不了。

2. 配置方式二:​

在 conf/server.xml 中配置 <Rescource>,在conf/content.xml 中配置全局资源引用 <RescourceLink> 方式(注意:Conf 下的 xml 配置文件是全局配置文件,在 Tomcat 服务器启动的时候会一一加载)。

2.1  server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server
port="8006"
shutdown="111">
<Listener className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
<Resource
name="xzg/orcl10gr2"
type="javax.sql.DataSource"
password="tiger"
driverClassName="oracle.jdbc.OracleDriver"
maxIdle="2"
maxWait="5000"
username="scott"
url="jdbc:oracle:thin:@xizhiguang:1521:orcl"
maxActive="20"/>
<Resource
name="xzg/mysql"
type="javax.sql.DataSource"
password="javaduke"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="javauser"
url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"
maxActive="20"/>
</GlobalNamingResources>
<Service
name="Catalina">
<Connector
port="8080"
redirectPort="8443"
minSpareThreads="25"
connectionTimeout="20000"
uRIEncoding="GBK"
maxSpareThreads="75"
maxThreads="150">
</Connector>
<Connector
port="8009"
redirectPort="8443"
protocol="AJP/1.3">
</Connector>
<Engine
defaultHost="localhost"
name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
<Host
appBase="webapps"
name="localhost">
</Host>
</Engine>
</Service>
</Server>

2.2  context.xml

<!-- The contents of this file will be loaded for each web application -->
<Context privileged='true'
reloadable="true">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->

<ResourceLink
global="xzg/orcl10gr2"
auth="Container"
type="javax.sql.DataSource"
name="xzg/orcl10gr2"/>
<ResourceLink
global="xzg/mysql"
auth="Container"
type="javax.sql.DataSource"
name="xzg/mysql"/>
</Context>

3. 配置方式三:​

又如,建一个应用的发布目录 {installDir}/webapps/test,相应的在 {installDir}/conf/Catalina/localhost/ 目录下建立一个针对发布目路的上下文配置 test.xml 文件。Server.xml 配置文件中只需定义全局的 <Rescource> 资源引用。

如: D:/WAS/apache-tomcat-5.5.20/conf/Catalina/localhost/test.xml, 文件的内容如下。

<?xml version="1.0" encoding="UTF-8"?>
<Context
crossContext="true"
privileged="true"
reloadable="true">
<ResourceLink
global="xzg/orcl10gr2"
auth="Container"
type="javax.sql.DataSource"
name="xzg/orcl10gr2"/>
<ResourceLink
global="xzg/mysql"
auth="Container"
type="javax.sql.DataSource"
name="xzg/mysql"/> <WatchedResource>D:/was/apache-tomcat-5.5.20/conf/context.xml</WatchedResource>
</Context>

标签:xml,配置文件,Tomcat,笔记,xzg,conf,mysql,type,name
From: https://blog.51cto.com/u_15907753/5926266

相关文章

  • JS高程8.1.1属性的类型笔记
    1.对象概念:对象是一组属性的无序集合。2.对象属性的类型:(1)数据属性:数据属性包含一个保存数据值的位置。值会从这个位置读取,也会写入到这个位置。数据属性有四个特性描述它......
  • sklearn学习笔记10:线性回归
    OverridetheentrypointofanimageIntroducedinGitLabandGitLabRunner9.4.Readmoreaboutthe extendedconfigurationoptions.Beforeexplainingtheav......
  • SpringBoot打war包,放Tomcat部署启动报错
    本人用的Jeecg-boot3.4.4最新版本打war包,按照官方文档war部署方式改了之后,启动tomcat就报如下错09-Dec-202215:08:01.902警告[localhost-startStop-1]org.apache.ca......
  • 尚硅谷-尚品汇笔记
    Author:gavin视频地址P35swiper基本使用快速生成轮播图步骤执行npmi-Sswiper@5,添加swiper库,因为6可能有bug,所以用5,引包(css),在main.js中引入impor......
  • C++笔记(自用)
    《EffectiveC++》条款11在operator=中处理“自我赋值”自我赋值证同测试:if(this==&rhs)return*this;影响并行处理效率记住副本:type*memberO=member;pmember=ne......
  • HTML速查笔记
    一.html结构  <html>    <head>      head内的标签标用户是看不到的,是给浏览器看的,主要定义一些配置      放置head内常用的标签 ......
  • CSS速查笔记
    什么是CSS?控制页面样式的,通常放在HTML的head标签内使用CSS结构选择器{css样式}css样式:{属性:值,属性:值,属性:值}CSS的引入方式有3种:一般都是在html种的head标签内加css......
  • Drone自动部署配置文件
    .drone.yml点击查看代码kind:pipeline#定义对象类型,还有secret和signature两种类型type:docker#定义流水线类型,还有kubernetes、exec、ssh等类型name:build......
  • MyEclipse配置Tomcat
    Tomcat:Tomcat是Apache软件基金会(ApacheSoftwareFoundation)的Jakarta项目中的一个核心项目,由Apache、Sun和其他一些公司及个人共同开发而成。由于有了Sun的参与和支持,最......
  • springmvc案例(依赖,插件、配置文件、controller层、jsp页面展示)
    第一步:创建一个maven的web工程第二步:进行导入依赖(spring的依赖应该也需要)<!--mvc的依赖--><dependency><groupId>org.springframework</groupId><artifac......