tomcat server.xml设置Context指定webapp访问路径引起的context.xml无效
通过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配置参考:
<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>
**antiJARLocking **
If true, the Tomcat classloader will take extra measures to avoid JAR file locking when resources are accessed inside JARs through URLs. This will impact startup time of applications, but could prove to be useful on platforms or configurations where file locking can occur. If not specified, the default value is false.
antiJARLocking is a subset of antiResourceLocking and therefore, to prevent duplicate work and possible issues, only one of these attributes should be set to true at any one time.
antiResourceLocking If true, Tomcat will prevent any file locking. This will significantly impact startup time of applications, but allows full webapp hot deploy and undeploy on platforms or configurations where file locking can occur. If not specified, the default value is false.
antiJARLocking is a subset of antiResourceLocking and therefore, to prevent duplicate work and possible issues, only one of these attributes should be set to true at any one time.
Please note that setting this to true has some side effects, including the disabling of JSP reloading in a running server: see Bugzilla 37668.
Please note that setting this flag to true in applications that are outside the appBase for the Host (the webapps directory by default) will cause the application to be deleted on Tomcat shutdown. You probably don't want to do this, so think twice before setting antiResourceLocking=true on a webapp that's outside the appBase for its Host.