我试图在Weblogic Server中配置Spring应用程序。 我无法使用JNDI Weblogic数据源:
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;
}
}
错误是:
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'
我已经阅读并尝试了谷歌和本网站其他帖子的大量解决方案,但我找不到任何有效的解决方案。