简体   繁体   English

配置错误。 找不到 Class [com.mysql.cj.jdbc.Driver]。 EclipseLink, MySQL 驱动程序

[英]Configuration error. Class [com.mysql.cj.jdbc.Driver] not found. EclipseLink, MySQL driver

I am trying to learn JPA using EclipseLink.我正在尝试使用 EclipseLink 学习 JPA。 I am using Mysql as my DB.我正在使用 Mysql 作为我的数据库。 I have added the all the dependencies required and below is my pom.xml我已经添加了所有需要的依赖项,下面是我的 pom.xml

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.7.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>javax.persistence</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.1.1</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.11</version>
        <scope>runtime</scope>
    </dependency>

</dependencies>

The issue is that even though maven has downloaded all the required jars for mysql jdbc connector I am getting Exception Description: Configuration error.问题是,即使 maven 已经为 mysql jdbc 连接器下载了所有必需的 jars,我仍收到异常描述:配置错误。 Class [com.mysql.cj.jdbc.Driver] not found.找不到 Class [com.mysql.cj.jdbc.Driver]。 Following are the version I am using: 1. Mysql JDBC connector: 8.0.11 2. Eclipselink: 2.7.1 3. JPA: 2.2.0以下是我使用的版本:1. Mysql JDBC 连接器:8.0.11 2. Eclipselink:2.7.1 3. JPA:2.2.0

Attached is the screenshot of my Maven dependencies jars.附上我的Maven依赖jars的截图。

I tried all the suggestions from other threads on stackoverflow but couldn't resolve the issue.我尝试了 stackoverflow 上其他线程的所有建议,但无法解决问题。

Appreciate your help and thanks in advance !感谢您的帮助,并提前致谢!

Below is my persistence.xml下面是我的坚持。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="Eclipselink_JPA" transaction-type="RESOURCE_LOCAL">

      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
      <exclude-unlisted-classes>false</exclude-unlisted-classes>

      <properties>
         <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
         <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpadb"/>
         <property name="javax.persistence.jdbc.user" value="root"/>
         <property name="javax.persistence.jdbc.password" value="root"/>
         <property name="eclipselink.logging.level" value="FINE"/>
         <property name="eclipselink.ddl-generation" value="create-tables"/>
      </properties>

   </persistence-unit>
</persistence>

Also, adding the error stack trace:此外,添加错误堆栈跟踪:

[EL Fine]: server: 2018-06-24 17:33:10.619--Thread(Thread[main,5,main])--Configured server platform: org.eclipse.persistence.platform.server.NoServerPlatform [EL Info]: 2018-06-24 17:33:11.065--ServerSession(1101598632)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.6.5.v20170607-b3d05bd [EL Severe]: ejb: 2018-06-24 17:33:11.068--ServerSession(1101598632)--Thread(Thread[main,5,main])--Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.6.5.v20170607-b3d05bd): org.eclipse.persistence.exceptions.DatabaseException Exception Description: Configuration error. [EL Fine]: server: 2018-06-24 17:33:10.619--Thread(Thread[main,5,main])--配置的服务器平台:org.eclipse.persistence.platform.server.NoServerPlatform [EL Info ]: 2018-06-24 17:33:11.065--ServerSession(1101598632)--Thread(Thread[main,5,main])--EclipseLink,版本:Eclipse 持久性服务 - 2.6.5.v20170607-b3d05bd [EL严重]: ejb: 2018-06-24 17:33:11.068--ServerSession(1101598632)--Thread(Thread[main,5,main])--Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.6.5 .v20170607-b3d05bd): org.eclipse.persistence.exceptions.DatabaseException 异常描述:配置错误。 Class [com.mysql.cj.jdbc.Driver] not found.找不到 Class [com.mysql.cj.jdbc.Driver]。 Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.6.5.v20170607-b3d05bd): org.eclipse.persistence.exceptions.DatabaseException Exception Description: Configuration error.线程“main”中的异常 javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.6.5.v20170607-b3d05bd): org.eclipse.persistence.exceptions.DatabaseException 异常描述:配置错误。 Class [com.mysql.cj.jdbc.Driver] not found.找不到 Class [com.mysql.cj.jdbc.Driver]。 at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:818) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:207) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:307) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:303) at practice.JPA.persistence.App.main(App.java:17) Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.6.5.v20170607-b3d05bd): org.eclipse.persistence.exceptions.DatabaseException Exception Description: Con at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:818) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:207) at org.eclipse.persistence.internal .jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:307) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl .java:303) at practice.JPA.persistence.App.main(App.java:17) Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.6.5.v20170607-b3d05bd): org8878317887831 .exceptions.DatabaseException异常描述:Con figuration error.形象错误。 Class [com.mysql.cj.jdbc.Driver] not found.找不到 Class [com.mysql.cj.jdbc.Driver]。 at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:89) at org.eclipse.persistence.sessions.DefaultConnector.loadDriverClass(DefaultConnector.java:267) at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:85) at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162) at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:214) at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:776) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:265) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.882132469458 at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:89) at org.eclipse.persistence.sessions.DefaultConnector.loadDriverClass(DefaultConnector.java:267) at org.eclipse.persistence.sessions.DefaultConnector.connect (DefaultConnector.java:85) at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162) at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:214) at org. eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:776) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:265) at org.eclipse.persistence.internal.jpa. EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.882132469458 88:734)... 5 more 88:734)... 还有 5 个

My project uses MySQL with EclipseLink implementation of JPA, and works fine.我的项目使用 MySQL 和 JPA 的 EclipseLink 实现,并且工作正常。 My pom file:我的pom文件:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.19</version>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.jpa</artifactId>
    <version>2.7.6</version>
</dependency>

I think i'm too late, but may help anyone.我想我来不及了,但可以帮助任何人。 In my case i'm using mysql-connector-java3.1.11 and get the same error.在我的例子中,我使用的是 mysql-connector-java3.1.11 并得到相同的错误。 After trying some other solutions that didn't work, i've checked the source code of "persistence.xml" and changed the following line: <property name="javax.persistence.cj.jdbc.driver" value="com.mysql.jdbc.Driver"/> to <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> (removing "cj" from the string) After that i got the program run without problems.在尝试了一些其他无效的解决方案后,我检查了“persistence.xml”的源代码并更改了以下行: <property name="javax.persistence.cj.jdbc.driver" value="com.mysql.jdbc.Driver"/><property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> (从字符串中删除“cj”)之后,我的程序运行没有问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java netbeans新的驱动程序类是`com.mysql.cj.jdbc.Driver&#39;。 - java netbeans The new driver class is `com.mysql.cj.jdbc.Driver' 无法从 HikariConfig 加载驱动程序 class com.mysql.cj.jdbc.Driver - Failed to load driver class com.mysql.cj.jdbc.Driver from HikariConfig 我用驱动<com.mysql.cj.jdbc.driver> ,但“junit test”不断导致错误</com.mysql.cj.jdbc.driver> - I use the driver <com.mysql.cj.jdbc.Driver>, but 'junit test' keep causing error 应用程序无法加载请求的 class:com.mysql.cj.Z84BEFFD3A0D49636A58CE6080CAADriver.8 - Application could not load requested class : com.mysql.cj.jdbc.Driver Liquibase Windows MySQL - Cannot find database driver: com.mysql.cj.jdbc.Driver - Liquibase Windows MySQL - Cannot find database driver: com.mysql.cj.jdbc.Driver JPA、Maven 和 MySQL。 配置错误。 Class [com.mysql.jdbc.Driver] 未找到 - JPA, Maven and MySQL. Configuration error. Class [com.mysql.jdbc.Driver] not found 无法加载驱动程序 class com.mysql.cj.jdbc.Driver 在 HikariConfig class 加载器或线程上下文类加载器中 - Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader centos8安装azkaban加载class`com.mysql.jdbc.Driver'。 这已被弃用。 新的驱动程序 class 是`com.mysql.cj.jdbc.Driver' - centos8 install azkaban Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' 异常描述:配置错误。 在Netbeans上找不到类[com.mysql.jdbc.Driver] - Exception Description: Configuration error. Class [com.mysql.jdbc.Driver] not found at Netbeans Caused by: java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl - Caused by: java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM