title: How does Tomcat inject the JNDI component-local context?
body: <p>In Tomcat, you can specify resources (JDBC connection, Javax mail sessions, etc.) in context.xml, reference them in web.xml, and then load them in Java like so:</p>
  
  <pre><code>Context ctx = new InitialContext();
  DataSource dataSource = (DataSource)ctx.lookup("java:/comp/env/jdbc/myDB");
  </code></pre>
  
  <p>I'm interested in what magical voo doo is going on here! I would have expected the need to inject the <code>InitialContext</code> constructor with a hashtable or some other object, thereby injecting it with everything defined in context.xml and web.xml. But it's a no-arg constructor!!!</p>
  
  <p>So I ask: what does Tomcat do to fill in the "missing link" between the 2 XML files and the <code>InitialContext</code> no-arg constructor so that the <code>DataSource</code> is magically available from the <code>ctx</code> instance? Thanks in advance!</p>