简体   繁体   中英

tomcat7 doesn't read context xml file

I would like to specify context for db in xml file.

  <Context path="/db3" docBase="C:/my/workspace/db3/">

 <Resource name="jdbc/ksidb" auth="Container" 
        type="javax.sql.DataSource"
        description="Books" 
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/ksidb"
        username="root"
        password="root"
        maxActive="20" /> 
</Context>

I've read that I should copy that file to /webapps tomcat catalogoue. I did this but tomcat7 doesn't read the file. Do you know why? What to do? Thx.

What you read is wrong. I'd question other advice from that source if it told you something so completely false. Per the Tomcat docs , your options for placing the context configuration are as follows:

  • In an individual file at /META-INF/context.xml inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to application's base file name plus a ".xml" extension.
  • In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.
  • Inside a Host element in the main conf/server.xml.

I highly recommend you visit the linked docs to learn more about the correct way to configure Tomcat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM