title: Spring Weblogic JNDI Not Found
body: <p>i'm trying to configure a Spring Application in Weblogic Server.
  I can't use the JNDI Weblogic Datasource:</p>
  
  <pre><code>    package com.report.beans.config;
  
  import java.util.Properties;
  
  import javax.sql.DataSource;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  
  @Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories(basePackages={"com.report.model.repository"})
  @PropertySource("classpath:database.properties")
  public class AppConfig {
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
          LocalContainerEntityManagerFactoryBean factoryBean = 
                  new LocalContainerEntityManagerFactoryBean();
  
          factoryBean.setDataSource(dataSource());
          factoryBean.setPackagesToScan(new String[] {"com.report.model.entity"});
  
          HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
          vendorAdapter.setShowSql(true);
  
  
          factoryBean.setJpaVendorAdapter(vendorAdapter);
  
          Properties additionalProperties = new Properties();
          additionalProperties.put("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
          additionalProperties.put("show_sql", "false");
          additionalProperties.put("javax.persistence.validation.mode", "NONE");
          additionalProperties.put("hibernate.cache.use_second_level_cache", "false");
          additionalProperties.put("hibernate.cache.use_query_cache", "false");
          additionalProperties.put("hibernate.order_updates", "TRUE");
  
          factoryBean.setJpaProperties(additionalProperties);
  
  
          return factoryBean;
      }
  
      @Bean
      public DataSource dataSource() {
          final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
          dsLookup.setResourceRef(true);
          DataSource dataSource = dsLookup.getDataSource("jdbc/DataSource");
          return dataSource;
      }
  
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>    Error creating bean with name 'entityManagerFactoryBean' defined in com.report.beans.config.AppConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactoryBean' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in com.report.beans.config.AppConfig: 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 'jdbc/DataSource'; nested exception is javax.naming.NameNotFoundException: Unable to resolve 'jdbc.DataSource'. Resolved 'jdbc'; remaining name 'DataSource'
  </code></pre>
  
  <p>I have read and tried a lot of solutions from google and others post of this site, but i can't find any valid solution.</p>