简体   繁体   中英

Tomcat context.xml and context.properties file

I have tomcat's context.xml file with references to the context.properties file

<Context sessionCookiePath="/" path="/">
<Resource name="jdbc/dbwriter" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          driverClassName="com.mysql.jdbc.Driver"
          type="javax.sql.DataSource"
          url="jdbc:mysql://${context.ip}:3306/test" username="${user}"
          password="${pass}" />
</Context>

The context.properties file looks like:

context.ip=localhost
user=admin
pass=admin

But it seems that tomcat does not load the properties file and tries to resolve jdbc:mysql://${context.ip}:3306 . What am I doing wrong?

For build I am using maven. Maybe it should fill up the property placeholders?

EDIT: the context.properties file is located in side WEB-INF/classes folder, and context.xml is located in the META-INF folder inside the WAR file.

There is little point shipping your context.properties file as part of the web application. You might as well have the build system do the property replacement for you.

If you want to keep the property definitions, Tomcat will pick up those properties if you add them to the catalina.properties file located in $CATALINA_BASE/conf

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