【问题标题】:How can I configure my tomcat application using server.xml?如何使用 server.xml 配置我的 tomcat 应用程序?
【发布时间】:2016-12-28 03:35:53
【问题描述】:

我有一个部署在 Tomcat 中的 webapp。

webapp 使用db.properties 文件来解析applicationContext.xml 中的dataSource bean 属性:

<context:property-placeholder location="file:${catalina.home}/conf/db.properties"/>

在这个例子中db.properties文件被放置在Tomcat的公共/conf/目录中。

我想把它放在不常见的/conf/,而是放在一个单独的子目录中,比如/conf/myapp/,并且myapp不应该在应用程序源中配置,而是在Tomcat设置中,比如server.xml

我需要它来部署这个 web 应用的两个副本,但它们应该适用于不同的数据库。

我该怎么做?

更新

这是我来自server.xmlservice

<Service name="train">
    <Connector port="8888" protocol="HTTP/1.1" connectionTimeout="20000" compression="on" compressionMinSize="2048" noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,text/json,application/x-javascript,application/javascript,application/json"/>
    <Engine name="trainings" defaultHost="localhost">
        <Host name="localhost" appBase="webapps">
            <Context docBase="trs" path="" />              
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/train/int" prefix="access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
        </Host>
    </Engine>
</Service>

【问题讨论】:

    标签: java tomcat web-applications


    【解决方案1】:
    1. &lt;context:property-placeholder/&gt; 放在applicationContext.xml 中
    2. &lt;Environment name="db.host" value="localhost" type="java.lang.String" override="false"/&gt; 在 server.xml 中的 Context 部分
    3. 只需在应用程序中使用 ${db.host}。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-09
      • 2023-03-19
      相关资源
      最近更新 更多