You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已添加依赖仍报java.lang.ClassNotFoundException: javax.persistence.Persistence

问题描述

尽管已添加JPA依赖,且persistence.xml文件放置在正确位置,但仍遇到错误。需要说明的是,Java应用的测试类已成功创建数据库表,当前在控制器中通过以下代码连接持久化:

private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("unit");
private static EntityManager entityManager = emf.createEntityManager();
private static EntityTransaction transactionObj = entityManager.getTransaction();

项目使用的Maven依赖(pom.xml)

<dependencies>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.12</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jakarta.servlet.jsp.jstl</artifactId>
        <version>1.2.6</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.5.1</version>
    </dependency>
</dependencies>

项目结构可参考对应截图。

内容的提问来源于stack exchange,提问作者najlae01

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 03:05:41