小编Aym*_*ane的帖子

Spring找不到类[org.hibernate.ejb.HibernatePersistence]

我正在研究eclipse上的java spring项目,当我试图通过JUnit测试运行项目时,我得到并且错误:找不到类[org.hibernate.ejb.HibernatePersistence].我找了很多类似的问题,没有人可以解决我的问题.我正确地构建和重建项目,但仍然是同样的问题.

首先是我的JUnit测试:

 @Test
public void test() {
    try {
        ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext(
                new String[] { "applicationContext.xml" });
        assertTrue(true);
    } catch (Exception e) {
        assertTrue(e.getMessage(), false);
    }

}
Run Code Online (Sandbox Code Playgroud)

这是错误:

 org.springframework.context.support.ClassPathXmlApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Cannot find class [org.hibernate.ejb.HibernatePersistence]
Run Code Online (Sandbox Code Playgroud)

这是我的persistence.xml文件:

 <?xml version="1.0" encoding="UTF-8"?>
 <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="GK_SHOP" …
Run Code Online (Sandbox Code Playgroud)

spring hibernate jpa persistence.xml

8
推荐指数
1
解决办法
3943
查看次数

标签 统计

hibernate ×1

jpa ×1

persistence.xml ×1

spring ×1