title: Unable to access Weblogic datasource through JNDI name using Spring Data JPA
body: <p>I am using Weblogic 12c and I have configured my datasources like this:</p>
  
  <p><a href="https://i.stack.imgur.com/AHqky.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AHqky.png" alt="enter image description here"></a></p>
  
  <p>Notice that they are all deployed on target "AdminServer". Also, the "Name" field and "JNDI Name" field are identical. For example, suppose one datasource's name is "MYDS".</p>
  
  <p>Now, when I try to acquire that datasource through Spring Data JPA like this:</p>
  
  <pre><code>    @Bean
      @Primary
      public DataSource businessDataSource() throws IllegalArgumentException, NamingException {
          JndiObjectFactoryBean dataSource = new JndiObjectFactoryBean();
          dataSource.setResourceRef(true);
          dataSource.setJndiName("MYDS");
          dataSource.afterPropertiesSet();
  
          return (DataSource) dataSource.getObject();
      }
  </code></pre>
  
  <p>I get the following error when trying to deploy the war file to weblogic:</p>
  
  <blockquote>
    <p>Bean instantiation via factory method failed; nested exception is
    org.springframework.beans.BeanInstantiationException: Failed to
    instantiate [javax.sql.DataSource]: Factory method
    'businessDataSource' threw exception; nested exception is
    javax.naming.NameNotFoundException: Unable to resolve 'MYDS'. Resolved
    ''; remaining name 'MYDS'</p>
  </blockquote>
  
  <p>Also I see this error:</p>
  
  <blockquote>
    <p>DEBUG o.s.jndi.JndiObjectFactoryBean - Converted JNDI name
    [java:comp/env/MYDS] not found - trying original name [MYDS].
    javax.naming.NameNotFoundException: While trying to look up
    comp/env/MYDS in /app/myapp/webclient/404708050.; remaining name
    'comp/env/MYDS'</p>
  </blockquote>