title: Remote JNDI + Spring Boot + WebLogic, How to specify the context from the application.property?
body: <p>I am developing a project in Spring Boot and Spring Data, I want to use JNDI from WebLogic remote server.</p>
  
  <p>I have an old example which does not use Spring, It does it of the follow way:</p>
  
  <pre><code>DataSource pool = null; Hashtable ht = null;
  ht = new Hashtable( );
  ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
  ht.put(Context.PROVIDER_URL,"t3://192.151.120.180:7003,192.151.121.180:7005");
  ht.put(weblogic.jndi.WLContext.ENABLE_SERVER_AFFINITY, "true");
  env =  new InitialContext(ht);
  pool = (DataSource) env.lookup("jdbc.conPesos");
  </code></pre>
  
  <p>I want to do the same connection, but from <code>application.property</code> file (or <code>application.yml</code> file) with Spring Boot .</p>
  
  <p>It is my code:</p>
  
  <pre><code> spring:
       datasource:
           driver-class-name: oracle.jdbc.OracleDriver
           url: t3://192.151.120.180:7003
           jndi-name: java:/comp/env/jdbc/conPesos
  </code></pre>
  
  <p>I got the mistake:</p>
  
  <blockquote>
    <p>Error creating bean with name 'dataSource' defined in class path
    resource [----]: Bean instantiation via factory method failed; nested
    exception is org.springframework.beans.BeanInstantiationException:
    Failed to instantiate [javax.sql.DataSource]: Factory method
    'dataSource' threw exception; nested exception is
    org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException:
    Failed to look up JNDI DataSource with name
    'java:/comp/env/jdbc/conPesos'; 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>To resolve the mistake, I created a <code>@configuration</code> class with the follow code:</p>
  
  <pre><code> @Bean public DataSource dataSource() throws NamingException {
       Context ctx ;
       DataSource dataSource;
       Hashtable&lt;String, String&gt; ht;
       NamedParameterJdbcTemplate np;
  
       ht = new Hashtable&lt;&gt;();
       ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
       ht.put(Context.PROVIDER_URL, "t3://192.151.120.180:7003");
       ht.put(weblogic.jndi.WLContext.ENABLE_SERVER_AFFINITY, "true");
       ctx = new InitialContext(ht);
  
       dataSource=(DataSource) ctx.lookup("jdbc.conPesos");
       return dataSource; }
  </code></pre>
  
  <p>Also I had to write <code>SpringBootApplication(exclude = JmxAutoConfiguration.class)</code> in the main class. It works fine, however I would like to do it from the <code>application.property</code> file, but I do not know how I can add the  INITIAL_CONTEXT_FACTORY property in that file.</p>
  
  <p>Does someone know it?</p>