【发布时间】:2015-01-14 09:40:21
【问题描述】:
有人尝试将 spring-data-jpa 与 java-ee 应用程序集成吗? 我使用 glassfish3 作为应用程序容器。
我按照官方 spring-data-jpa 教程创建了一个类:
public class EntityManagerFactoryProducer {
@Produces
@ApplicationScoped
public EntityManagerFactory createEntityManagerFactory() {
return Persistence.createEntityManagerFactory("myPU");
}
public void close(@Disposes EntityManagerFactory entityManagerFactory) {
entityManagerFactory.close();
}
@Produces
@RequestScoped
public EntityManager createEntityManager(EntityManagerFactory entityManagerFactory) {
return entityManagerFactory.createEntityManager();
}
public void close(@Disposes EntityManager entityManager) {
entityManager.close();
}
}
但是当我尝试部署我的应用程序时,我遇到了一个异常:
Error occurred during deployment: Exception while preparing the app : Could not resolve a persistence unit corresponding to the persistence-context-ref-name [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean/entityManager] in the scope of the module called [App]. Please verify your application.. Please see server.log for more details.
Command deploy failed.
我错过了什么?我还应该有另一个配置文件还是一些 xml 文件?
【问题讨论】:
-
我认为问题可能在于您没有在 persistence.xml 中声明的名称为“myPU”的持久性单元。但我也不认为这是正确的做法。详情见我的回答。
-
PU 声明正确。
标签: java jakarta-ee cdi glassfish-3 spring-data-jpa