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