Spring Data JPA @EnableJpaRepositories配置详解(2)

1 @Bean 2 public LocalContainerEntityManagerFactoryBean entityManagerFactory() { 3 LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); 4 entityManagerFactoryBean.setDataSource(dataSource()); 5 entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); 6 entityManagerFactoryBean 7 .setPackagesToScan(env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN)); 8 entityManagerFactoryBean.setJpaProperties(hibProperties()); 9 return entityManagerFactoryBean; 10

10)transactionManagerRef

事务管理工厂引用名称,对应到@Bean注解对应的方法

1

2

3

4

5

6

 

@Bean

public JpaTransactionManager transactionManager() {

    JpaTransactionManager transactionManager = new JpaTransactionManager();

    transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());

    return transactionManager;

}

 

Spring Data 的详细介绍请点这里
Spring Data 的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/0ba53cbeb2157d1ee4ac1da5f8f922de.html