title: Spring Jndi Configuration, Server.xml
body: <p>I have a problem setting up my configuration for JNDI with Spring.  I checked the other posts but could not get my problem solved.  I am using Tomcat 6 as my container.  From my understanding I need to set up a resource on the server.  So in my <code>server.xml</code> file I have this:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;GlobalNamingResources&gt;
      &lt;Resource auth=&quot;Container&quot; driverClassName=&quot;org.postgresql.Driver&quot;
              maxActive=&quot;100&quot; maxIdle=&quot;5&quot; maxWait=&quot;10000&quot;
              minEvictableIdleTimeMillis=&quot;60000&quot; name=&quot;jdbc/myTomcatPool&quot;
              password=&quot;password&quot; testOnBorrow=&quot;true&quot; testWhileIdle=&quot;true&quot;
              timeBetweenEvictionRunsMillis=&quot;10000&quot; type=&quot;javax.sql.DataSource&quot;
              url=&quot;jdbc:postgresql://localhost:5432/postgis&quot; username=&quot;postgres&quot;
              validationQuery=&quot;SELECT 1&quot;/&gt;
  &lt;/GlobalNamingResources&gt;
  </code></pre>
  <p>I have the following in my <code>spring-context.xml</code> (which is on the classpath):</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;jee:jndi-lookup id=&quot;geoCodeData&quot; jndi-name=&quot;java:comp/env/jdbc/myTomcatPool&quot; /&gt;
  
  &lt;bean id=&quot;geoCodeService&quot; class=&quot;com.sample.SampleImpl&quot;&gt;
      &lt;property name=&quot;dataSource&quot; ref=&quot;geoCodeData&quot;/&gt;
  &lt;/bean&gt;
  </code></pre>
  <p>I then have this in file <code>META-INF/context.xml</code>:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Context path=&quot;/myApp&quot; reloadable=&quot;true&quot; cacheMaxSize=&quot;51200&quot;
          cacheObjectMaxSize=&quot;2560&quot;&gt;
      &lt;ResourceLink global=&quot;jdbc/myTomcatPool&quot; name=&quot;jdbc/myTomcatPool&quot;
              type=&quot;javax.sql.DataSource&quot;/&gt;
  &lt;/Context&gt;
  </code></pre>
  <p>My server starts up free of errors.</p>
  <p>When I try to run the following test (that worked before I added the JNDI code):</p>
  <pre><code>public class Test {
      public static void main(String[] args) {
          ApplicationContext ctx =
              new ClassPathXmlApplicationContext(&quot;spring-context.xml&quot;);
      }
  }
  </code></pre>
  <p>I get the following error:</p>
  <blockquote>
  <p>Exception in thread &quot;main&quot; org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geoCodeData': Invocation of init method failed;</p>
  <p>nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial</p>
  </blockquote>
  <p>Is my configuration wrong or is the way I am trying to run the test incorrect?</p>