【问题标题】:Tomcat context.xml and context.properties fileTomcat context.xml 和 context.properties 文件
【发布时间】:2014-06-18 08:20:34
【问题描述】:

我有 tomcat 的 context.xml 文件,其中引用了 context.properties 文件

<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>

context.properties 文件如下所示:

context.ip=localhost
user=admin
pass=admin

但似乎tomcat没有加载属性文件并尝试解析jdbc:mysql://${context.ip}:3306。我做错了什么?

对于构建,我使用的是 maven。也许它应该填充属性占位符?

编辑:context.properties 文件位于 WEB-INF/classes 文件夹中,context.xml 位于 WAR 文件内的 META-INF 文件夹中。

【问题讨论】:

    标签: java maven tomcat


    【解决方案1】:

    将您的 context.properties 文件作为 Web 应用程序的一部分进行传送没有什么意义。您不妨让构建系统为您完成属性替换。

    如果您想保留属性定义,如果您将这些属性添加到 $CATALINA_BASE/conf 中的 catalina.properties 文件中,Tomcat 会选择这些属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 2013-02-28
      • 2015-11-17
      相关资源
      最近更新 更多