---
title: "tomcat server.xml设置Context指定webapp访问路径引起的context.xml无效"
author: "lym6520"
date: "2014-02-12T10:57:23Z"
tags: []
categories: ["企业架构"]
slug: "tomcat-server-xml-context-webapp-context-xml"
draft: false
lastmod: "2014-02-12T10:57:23Z"
id: 2015229
url: "https://lym6520.iteye.com/blog/2015229"
---

通过tomcat的server.xml设置来部署webapp，即在Host下增加Context节点，会引起webapp应用的META-INF/context.xml文件无效，如果context配置了数据源则可能会出现如下错误：

- - Cannot create JDBC driver of class '' for connect URL 'null'

所以如果是通过server.xml设置来部署webapp的，应当把context.xml配置也转移到server.xml中，这样就可以避免此类问题。

另外Context节点的属性 antiResourceLocking="true" antiJARLocking="true" 要慎用，如果配置上，部署的项目会copy一份到tomcat/temp目录下，如果上传的附件是保存在webapp目录下tomcat重启后附件就会丢失。

Context配置参考：

```xml

<Context reloadable="false" docBase="/usr/wwwroot/app1" path="">
	    <Resource name="jdbc/lxcy" auth="Container"
		type="javax.sql.DataSource" maxActive="40" maxIdle="20"
		maxWait="10000" driverClassName="com.mysql.jdbc.Driver"
		url="jdbc:mysql://127.0.0.1:3306/lxcy?characterEncoding=utf8"
		username="lxcy" 
		password="123456"
		testOnBorrow="true" testWhileIdle="true"
		validationQuery="select now()" />
	</Context>

```