title: Setting up JNDI connection with Spring Boot
body: <p>I'm trying to set up a JNDI database connection for my WAR file which will be deployed on WebLogic 12c. This is what I have:</p>
  
  <pre><code>@Bean
  public DataSource dataSource() throws DataSourceLookupFailureException {
    JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
  
    return dataSourceLookup.getDataSource("jndiName");
  }
  </code></pre>
  
  <p>In the <code>application.properties</code> file:</p>
  
  <pre><code>spring.datasource.jndi-name=jndiName
  </code></pre>
  
  <p>This is pieced together from two different sections of the Spring Boot guide:</p>
  
  <ul>
  <li><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html" rel="nofollow noreferrer">https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html</a></li>
  <li><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html#howto-configure-a-datasource" rel="nofollow noreferrer">https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html#howto-configure-a-datasource</a></li>
  </ul>
  
  <p>I am confused, why is <code>jndiName</code> stated twice? Am I following correctly - is this the correct way to set up?</p>
  
  <p>I am of the impression that Spring Boot will either automatically retrieve the JNDI name from <code>application.properties</code>, so that I do not need to hardcode the JNDI name into <code>getDataSource()</code>, or if I hardcode the JNDI name in then I wouldn't need to include that property in <code>application.properties</code> in the first place.</p>
  
  <p>From my interpretation, the two sections of the guide covering how to set up a JNDI connection appear to contradict each other. What am I getting wrong? What exactly is the correct way to set this up?</p>