title: How to select JNDI based on environment
body: <p>Is it somehow possible to select a JNDI Resource based on the value of a variable containing which environment to link to ?</p>
  
  <p>For example, in my domain I have 3 environments: DEV, QA and STAGE. I have a database called EcommReporting that exists for each of these environments. To cater for this, in my tomcat server's <code>server.xml</code> file, I have separate entries for <code>DEV_EcommReporting</code>, <code>QA_EcommReporting</code> and <code>STAGE_EcommReporting</code>.</p>
  
  <p>The question is, is there some way my code can just request for the JNDI resource named <code>EcommReporting</code> and provides an environment name, and then based on these two details the correct Resource is returned ?</p>
  
  <p>Here's now I'm defining a datasource bean using Spring:</p>
  
  <pre><code>   &lt;bean id="EcommReportingDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
          &lt;property name="jndiName" value="java:comp/env/jdbc/EcommReporting"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Then in my Tomcat server's context.xml (only showing the QA version), I have this:</p>
  
  <pre><code>&lt;ResourceLink name="jdbc/EcommReporting"
                  global="jdbc/QA_EcommReporting"
                  auth="Container"
                  type="javax.sql.DataSource" /&gt;
  </code></pre>
  
  <p>Lastly, in my Tomcat server's server.xml, I've defined the JNDI resource as follows:</p>
  
  <pre><code>&lt;Resource name="jdbc/QA_EcommReporting" 
        global="jdbc/QA_EcommReporting" 
        auth="Container" 
        type="javax.sql.DataSource" 
        driverClassName="com.mysql.jdbc.Driver" 
        url="jdbc:mysql://URLHERE.COM:3311/REPORTING" 
        username="username_here" 
        password="password_here" 
  
        maxActive="100" 
        maxIdle="20" 
        minIdle="5" 
        maxWait="10000"/&gt;
  </code></pre>
  
  <p>ads</p>