0
我有春季4應用程序,我想使用春季倉庫。我想包括彈簧jpa_hibernate春季4 +春季倉庫+休眠5:錯誤創建java配置
compile 'org.springframework.data:spring-data-jpa:1.11.4.RELEASE'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.0.5.Final'
,並創建配置像oficial spring doc:
@Configuration
@ComponentScan("my.domain")
@EnableJpaRepositories("my.domain")
@EnableTransactionManagement
public class ApplicationConfiguration {
@Bean
public Config getConfig() {
return ConfigLoader.load();
}
@Bean
@Autowired
public DataSource getDatasource(Config config) throws Exception {
Properties props = new Properties();
Config dbConfig = config.getConfig("db.config");
dbConfig.entrySet().forEach(entry -> props.put(entry.getKey(), entry.getValue().unwrapped()));
return new DataSourceFactory().createDataSource(props);
}
@Bean
@Autowired
public NamedParameterJdbcTemplate getJdbcTemplate(DataSource datasource) {
return new NamedParameterJdbcTemplate(datasource);
}
@Bean
@Autowired
public PlatformTransactionManager getTransactionManager(DataSource datasource) {
return new DataSourceTransactionManager(datasource);
}
@Bean
@Autowired
public EntityManagerFactory entityManagerFactory(DataSource datasource) {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setDataSource(datasource);
factory.afterPropertiesSet();
return factory.getObject();
}
@Bean
@Autowired
public PlatformTransactionManager transactionManager(DataSource datasource) {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(entityManagerFactory(datasource));
return txManager;
}
}
,但我得到的錯誤,當試圖運行的應用程序:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in my.ApplicationConfiguration:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
[javax.persistence.EntityManagerFactory]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.IllegalStateException:
Failed to determine Hibernate PersistenceProvider
我以前在springboot和配置存儲庫中的文件,但我沒有發現爲java配置彈簧worck實際的例子(不開機只有簡單的核心應用程序)
pls show full stacktrace – xyz
這是完整的堆棧跟蹤 – user5620472