title: Using JNDI for for my datasource and location of properties files
body: <p>I want to use jndi in my spring mvc application for 2 things:</p>
  
  <ol>
  <li>datasource settings</li>
  <li>store the location of my properties file so I can do a lookup in my code</li>
  </ol>
  
  <p>I actually have 2 applications, 1 is a spring mvc and the other is a spring so I'm planning on using the same jndi settings for both.</p>
  
  <p>Also, the 2 applications run on different contains (tomcat and jetty), I've never used jndi before so I hope I can define this in a single location and have both applications point to the same jndi file (assuming its a file).</p>
  
  <p>So as for #1, my datasource settings in my spring context file are currently:</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="url" value="jdbc:mysql://localhost/mydb_development"/&gt;
          &lt;property name="username" value="devuser1"/&gt;
          &lt;property name="password" value="123"/&gt;
  
          &lt;property name="maxActive" value="100"/&gt;
          &lt;property name="maxIdle" value="30"/&gt;
          &lt;property name="maxWait" value="1000"/&gt;
          &lt;property name="defaultAutoCommit" value="true"/&gt;
          &lt;property name="removeAbandoned" value="true"/&gt;
          &lt;property name="removeAbandonedTimeout" value="60"/&gt;
  
          &lt;property name="testOnBorrow" value="true"/&gt;
          &lt;property name="validationQuery" value="SELECT 1"/&gt;
  
      &lt;/bean&gt;
  </code></pre>
  
  <p><strong>Can someone tell me how I can extract this out to use JNDI, confused, is it a separate file that has to be in my class loader, or do I hard code the path in my spring context file?</strong></p>
  
  <p>And as for #2, in my code I am currently loading a properties file that is in my class path like:</p>
  
  <pre><code>ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  InputStream is = classLoader.getResourceAsStream("test.properties");
  </code></pre>
  
  <p>Now the test.properties file is in my classpath so it works out of the box, but what I want to know/understand is if I could somehow use jndi to lookup the location of the properties file (if that makes sense?) and not have this file in my classpath potentially.</p>
  
  <p>I did google around and I know in spring I can pull in jndi using:</p>
  
  <pre><code>&lt;jee:jndi-lookup id="dataSource" jndi-name="jdbc/mysqlDataSource" /&gt;
  </code></pre>
  
  <p>But what I don't understand is, where is the actual file that has the settings?  Can it be in a location other than my web.xml file?  (my other application again is using spring, but it is a daemon so it doesn't have a web.xml file).</p>
  
  <p>The goal for me is to be able to change the values of the jndi file (like username, passwords, file paths) and NOT have these embedded into a jar.  I want to be able to manually edit these files on the production server or dev servers and just restart the container.</p>