作者:哇哈时候_206 | 来源:互联网 | 2023-05-20 16:37
1> Vladimir..:
要使框架选择JpaRepository,您需要在配置中启用它 - 添加
@EnableJpaRepositories("your.package.with.jpa.repositories")
在你的@Configuration
文件中.
UPD
这是jpa存储库的示例配置:
@Bean
public DataSource dataSource(){
// configure your datasource
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
emfb.setDataSource(dataSource);
emfb.setPackagesToScan("your.package.with.model");
emfb.setJpaVendorAdapter(jpaVendorAdapter());
emfb.setJpaPropertyMap(jpaPropertiesMap());
return emfb;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
return new HibernateJpaVendorAdapter();
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactiOnManager= new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
public Map jpaPropertiesMap() {
Properties properties = new Properties();
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); // assumption based on your pom-file
properties.setProperty("hibernate.hbm2ddl.auto", "..."); // you need to google for appropriate option
return properties;
}