简体   繁体   English

如何使用server.xml配置雄猫应用程序?

[英]How can I configure my tomcat application using server.xml?

I've got a webapp that is deployed in Tomcat. 我有一个部署在Tomcat中的webapp。

The webapp uses a db.properties file to resolve dataSource bean properties in applicationContext.xml : db.properties应用程序使用db.properties文件来解析applicationContext.xml dataSource bean属性:

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

In this example db.properties file is placed in common /conf/ directory of the Tomcat. 在此示例中, db.properties文件位于Tomcat的common /conf/目录中。

And I want to place it not in common /conf/ , but in a separate subdirectory, like /conf/myapp/ , and myapp should be configured not in application sources, but in Tomcat settings, like server.xml . 而且我不想将其放置在公共/conf/ ,而是放置在单独的子目录中,例如/conf/myapp/ ,并且myapp不应配置在应用程序源中,而应配置在Tomcat设置中,例如server.xml

I need it to deploy two copies of this webapp, but they should work with different databases. 我需要它来部署此Web应用程序的两个副本,但它们应与其他数据库一起使用。

How can I do this? 我怎样才能做到这一点?

UPDATE 更新

Here's my service block from server.xml 这是我来自server.xml service

<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>
  1. place <context:property-placeholder/> in applicationContext.xml <context:property-placeholder/>放置在applicationContext.xml中
  2. <Environment name="db.host" value="localhost" type="java.lang.String" override="false"/> in server.xml in Context section Context部分中server.xml中的<Environment name="db.host" value="localhost" type="java.lang.String" override="false"/>
  3. just use ${db.host} in the application. 只需在应用程序中使用$ {db.host}。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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