title: Configure DataSource Using JNDI Using external Tomcat 9 Server: Spring Boot
body: <p>I have a SpringBootApplication, packaged as war file:</p>
  <pre><code>@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
  public class Application extends SpringBootServletInitializer {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
      
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(Application.class);
      }
  
  }
  </code></pre>
  <p>on the application.properties:</p>
  <pre><code>spring.datasource.jndi-name=java:comp/env/jdbc/bonanza
  </code></pre>
  <p>but on the logs I see those messages when I deploy the war in the Tomcat 9:</p>
  <pre><code>Name [spring.datasource.jndi-name] is not bound in this Context. Unable to find [spring.datasource.jndi-name].. Returning null.
  </code></pre>
  <p>the logs:</p>
  <pre><code>12:37:53.989 [main] DEBUG o.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/spring.datasource.jndi-name]
  12:37:53.989 [main] DEBUG o.s.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/spring.datasource.jndi-name] not found - trying original name [spring.datasource.jndi-name]. javax.naming.NameNotFoundException: Name [spring.datasource.jndi-name] is not bound in this Context. Unable to find [spring.datasource.jndi-name].
  12:37:53.990 [main] DEBUG o.springframework.jndi.JndiTemplate - Looking up JNDI object with name [spring.datasource.jndi-name]
  12:37:53.991 [main] DEBUG o.s.jndi.JndiPropertySource - JNDI lookup for name [spring.datasource.jndi-name] threw NamingException with message: Name [spring.datasource.jndi-name] is not bound in this Context. Unable to find [spring.datasource.jndi-name].. Returning null.
  12:37:53.995 [main] DEBUG o.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/spring.datasource.jndi-name]
  12:37:53.996 [main] DEBUG o.s.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/spring.datasource.jndi-name] not found - trying original name [spring.datasource.jndi-name]. javax.naming.NameNotFoundException: Name [spring.datasource.jndi-name] is not bound in this Context. Unable to find [spring.datasource.jndi-name].
  12:37:53.996 [main] DEBUG o.springframework.jndi.JndiTemplate - Looking up JNDI object with name [spring.datasource.jndi-name]
  12:37:53.997 [main] DEBUG o.s.jndi.JndiPropertySource - JNDI lookup for name [spring.datasource.jndi-name] threw NamingException with message: Name [spring.datasource.jndi-name] is not bound in this Context. Unable to find [spring.datasource.jndi-name].. Returning null.
  12:37:53.998 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'spring.datasource.jndi-name' in PropertySource 'configurationProperties' with value of type String
  </code></pre>
  <p>on my <code>tomcat9/conf/context.xml:</code></p>
  <pre><code> &lt;Resource  name=&quot;jdbc/bonanza&quot; 
                  auth=&quot;Container&quot; 
                  type=&quot;javax.sql.DataSource&quot;
                  maxTotal=&quot;100&quot; 
                  maxIdle=&quot;30&quot; 
                  maxWaitMillis=&quot;10000&quot;
                  username=&quot;a_usr&quot; 
                  password=&quot;Mu*7gydlcdstg100@&quot; 
                  driverClassName=&quot;com.mysql.jdbc.Driver&quot;
                  url=&quot;jdbc:mysql://172.175.77.55:3306/a_db&quot;
          /&gt;
  </code></pre>