如何配置将EntityManager中的JPA EntityManagerFactory注入spring bean

时间:2017-05-30 23:20:53

标签: java spring hibernate jpa spring-orm

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(datasource());
    em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    em.setJpaProperties(properties());
    em.setPersistenceUnitName("JPA_PU");
    em.setPackagesToScan("com.test.entity");
    return em;
}

从我的持久性配置中的bean声明中注入了这个  豆进入这个

 @PersistenceContext(unitName = "JPA_PU")
 private EntityManager em;

但不是

 @Autowired
 private EntityManagerFactory emf;

0 个答案:

没有答案