1. <small id='nIWQa'></small><noframes id='nIWQa'>

        <bdo id='nIWQa'></bdo><ul id='nIWQa'></ul>
      <tfoot id='nIWQa'></tfoot>

      1. <i id='nIWQa'><tr id='nIWQa'><dt id='nIWQa'><q id='nIWQa'><span id='nIWQa'><b id='nIWQa'><form id='nIWQa'><ins id='nIWQa'></ins><ul id='nIWQa'></ul><sub id='nIWQa'></sub></form><legend id='nIWQa'></legend><bdo id='nIWQa'><pre id='nIWQa'><center id='nIWQa'></center></pre></bdo></b><th id='nIWQa'></th></span></q></dt></tr></i><div id='nIWQa'><tfoot id='nIWQa'></tfoot><dl id='nIWQa'><fieldset id='nIWQa'></fieldset></dl></div>
      2. <legend id='nIWQa'><style id='nIWQa'><dir id='nIWQa'><q id='nIWQa'></q></dir></style></legend>

        Tomcat 8 - context.xml 在数据源中使用环境变量

        Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
          <legend id='YGXHa'><style id='YGXHa'><dir id='YGXHa'><q id='YGXHa'></q></dir></style></legend>

            1. <tfoot id='YGXHa'></tfoot>

              <small id='YGXHa'></small><noframes id='YGXHa'>

            2. <i id='YGXHa'><tr id='YGXHa'><dt id='YGXHa'><q id='YGXHa'><span id='YGXHa'><b id='YGXHa'><form id='YGXHa'><ins id='YGXHa'></ins><ul id='YGXHa'></ul><sub id='YGXHa'></sub></form><legend id='YGXHa'></legend><bdo id='YGXHa'><pre id='YGXHa'><center id='YGXHa'></center></pre></bdo></b><th id='YGXHa'></th></span></q></dt></tr></i><div id='YGXHa'><tfoot id='YGXHa'></tfoot><dl id='YGXHa'><fieldset id='YGXHa'></fieldset></dl></div>
                <bdo id='YGXHa'></bdo><ul id='YGXHa'></ul>

                    <tbody id='YGXHa'></tbody>
                • 本文介绍了Tomcat 8 - context.xml 在数据源中使用环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个使用数据源的 Tomcat 8 项目(见下文)

                  I have a Tomcat 8 project that uses a datasource (see below)

                  <Resource auth="Container" 
                            name="jdbc/JtmDS"  
                            driverClassName="org.apache.derby.jdbc.EmbeddedDriver" 
                            type="javax.sql.DataSource" 
                            username="xfer"
                            password="xfer10" 
                            url="jdbc:derby:/home/PUID/tm/control/JtmDB"                    
                            initialSize="25"
                            maxTotal="100" 
                            maxIdle="30" 
                            maxWaitMillis="10000"                                      
                            removeAbandonedOnBorrow="true"
                            removeAbandonedTimeout="20" />
                  

                  这很好用.

                  但是url是硬编码路径/home/PUID/tm/control/JtmDB

                  However the url is a hard-coded path /home/PUID/tm/control/JtmDB

                  当它投入生产时,路径的 PUID 部分将在众多系统中有所不同.我有一个环境变量集 export PUID=abcd应用程序的其余部分能够在适当的情况下使用诸如 System.getenv( )${env:PUID} 之类的东西.

                  When this gets into production the PUID part of the path will differ across numerous systems. I have an environment variable set export PUID=abcd The rest of the application is able to use things like System.getenv( ) or ${env:PUID} as and where appropriate.

                  这些都可以正常工作.

                  我的问题很简单:如何使 context.xml 中的 PUID 值成为可以从环境变量中读取的变量?

                  My question is very simply: How can I make the PUID value in my context.xml a variable that can be read from an environment variable?

                  推荐答案

                  我终于发现了我在这里真正需要做的事情......最后很简单.

                  I finally discovered what I actually needed to do here.... Quite simple in the end.

                  我在运行时向 Tomcat 传递了一个 java 参数,如下所示.

                  I passed in a java parameter to Tomcat at runtime as shown below.

                  我将以下位添加到 setenv.sh

                  export PUID=abcd
                  
                  JAVA_OPTS=-Dpuid=${PUID} 
                  

                  然后编辑我的 context.xml,如下所示

                  Then edited my context.xml as shown here

                  <Resource auth="Container" 
                            name="jdbc/JtmDS"  
                            driverClassName="org.apache.derby.jdbc.EmbeddedDriver" 
                            type="javax.sql.DataSource" 
                            username="xfer"
                            password="xfer10" 
                            url="jdbc:derby:/home/${puid}/tm/control/JtmDB"                    
                            initialSize="25"
                            maxTotal="100" 
                            maxIdle="30" 
                            maxWaitMillis="10000"                                      
                            removeAbandonedOnBorrow="true"
                            removeAbandonedTimeout="20" />
                  

                  所以现在我的 Tomcat 安装将读取此内容并能够为每个不同的 PUID 使用不同的路径.

                  So now my Tomcat installation will read this and be able to use a different path for each different PUID.

                  背景:这是可行的,因为 Tomcat 会自动在其配置文件中执行变量替换:

                  Background: This works because Tomcat will automatically perform variable substition in its configuration files:

                  Tomcat 配置文件被格式化为无模式 XML;元素并且属性区分大小写.

                  Tomcat configuration files are formatted as schemaless XML; elements and attributes are case-sensitive.

                  Apache Ant 风格的变量支持替换;一个名为 propname 的系统属性可以使用语法 ${propname} 在配置文件中使用.全部系统属性可用,包括使用 -D 设置的属性语法,那些由 JVM 自动提供的和那些在 $CATALINA_BASE/conf/catalina.properties 文件中配置.

                  Apache Ant-style variable substitution is supported; a system property with the name propname may be used in a configuration file using the syntax ${propname}. All system properties are available including those set using the -D syntax, those automatically made available by the JVM and those configured in the $CATALINA_BASE/conf/catalina.properties file.

                  Apache Tomcat 9 配置参考 - 概述

                  部分:

                  JAVA_OPTS=-Dpuid=${PUID}
                  

                  上面的描述是必要的,因为 Tomcat 只会读取 Java 系统属性(由 JVM 提供),但不是环境变量(由运行 JVM 的操作系统/运行时库提供).参数-D从同名的环境变量中设置一个Java系统属性.

                  describe above is necessary because Tomcat will only read Java system properties (which are provided by the JVM), but not environment variables (which are provided by the OS/runtime libraries that the JVM is running on). The parameter -D sets a Java system property from the environment variable of the same name.

                  这篇关于Tomcat 8 - context.xml 在数据源中使用环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                  <small id='Ig0Rx'></small><noframes id='Ig0Rx'>

                        <bdo id='Ig0Rx'></bdo><ul id='Ig0Rx'></ul>

                      • <tfoot id='Ig0Rx'></tfoot>
                        1. <i id='Ig0Rx'><tr id='Ig0Rx'><dt id='Ig0Rx'><q id='Ig0Rx'><span id='Ig0Rx'><b id='Ig0Rx'><form id='Ig0Rx'><ins id='Ig0Rx'></ins><ul id='Ig0Rx'></ul><sub id='Ig0Rx'></sub></form><legend id='Ig0Rx'></legend><bdo id='Ig0Rx'><pre id='Ig0Rx'><center id='Ig0Rx'></center></pre></bdo></b><th id='Ig0Rx'></th></span></q></dt></tr></i><div id='Ig0Rx'><tfoot id='Ig0Rx'></tfoot><dl id='Ig0Rx'><fieldset id='Ig0Rx'></fieldset></dl></div>
                            <tbody id='Ig0Rx'></tbody>
                          <legend id='Ig0Rx'><style id='Ig0Rx'><dir id='Ig0Rx'><q id='Ig0Rx'></q></dir></style></legend>