2

i'm trying to configure a Spring Application in Weblogic Server. I can't use the JNDI Weblogic Datasource:

    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;
    }

}

The error is:

    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'

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.

Ildelian
  • 1,278
  • 5
  • 15
  • 38
  • 1
    Possible duplicate of [How to lookup JNDI resources on WebLogic?](http://stackoverflow.com/questions/6500632/how-to-lookup-jndi-resources-on-weblogic) – Michael Peacock Mar 10 '17 at 22:01
  • I have try this solution, and i receive the same error: Caused by: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.DBHSPREPORTS'. Resolved 'jdbc'; remaining name 'DBHSPREPORTS' – Ildelian Mar 13 '17 at 12:53

0 Answers0