我用Spring和JDBC开发了一个项目,现在我正在尝试使用JPA配置我的Spring应用程序,我正在学习本教程。我在getObject()
方法geJpaTransactionManager
下收到错误。我已经提到了所有提到的JAR。我在这里错过任何东西吗?
@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan(basePackages = "net.jpa.spring")
public class AppConfig{
@Bean
public LocalEntityManagerFactoryBean getEntityManagerFactoryBean() {
LocalEntityManagerFactoryBean factoryBean = new LocalEntityManagerFactoryBean();
factoryBean.setPersistenceUnitName("LOCAL_PERSISTENCE");
return factoryBean;
}
@Bean
public JpaTransactionManager geJpaTransactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(getEntityManagerFactoryBean().getObject()); --> Getting error here
return transactionManager;
}
}
错误是
The method getObject() from the type AbstractEntityManagerFactoryBean refers to the missing type EntityManagerFactory
答案 0 :(得分:0)
我认为您可能没有导入hibernate-jpa。 Miber依赖项对于hibernate-jpa如下。这就是为什么编译器无法检测到EntityManagerFactory的原因。
<!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.0-api -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>