没有找到名为META-INF / services / javax.persistence.spi.PersistenceProvider的资源文件

时间:2018-04-22 11:55:29

标签: java maven jpa

我是一个刚开始学习使用JPA连接和管理虚拟机上的MySQL数据库的初学者,但我收到了这样的消息:

  

线程中的异常" main" javax.persistence.PersistenceException:找不到名为META-INF / services / javax.persistence.spi.PersistenceProvider的资源文件。请确保持久性提供程序jar文件位于类路径中。

我几乎查看了与该问题相关的StackOverflow上的每一篇文章,但我仍然无法解决它。

在pom.xml中,我有这些依赖项:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.9-rc</version>
</dependency>

<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>persistence-api</artifactId>
    <version>1.0.2</version>
</dependency>

这是我的persistence.xml文件:

<persistence-unit name="Eclipselink_JPA" transaction-type="RESOURCE_LOCAL">

    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://ip_address:port/jpadb"/>
        <property name="javax.persistence.jdbc.user" value="username"/>
        <property name="javax.persistence.jdbc.password" value="password"/>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    </properties>

</persistence-unit>

而且,这是代码:

public class CreateEmployee {

public static void main(String[] args) {

    EntityManagerFactory emfactory = Persistence.createEntityManagerFactory( "Eclipselink_JPA" );

    EntityManager entitymanager = emfactory.createEntityManager( );
    entitymanager.getTransaction( ).begin( );

    Employee employee = new Employee( );
    employee.setEid( 1201 );
    employee.setEname( "Gopal" );
    employee.setSalary( 40000 );
    employee.setDeg( "Technical Manager" );

    entitymanager.persist( employee );
    entitymanager.getTransaction( ).commit( );

    entitymanager.close( );
    emfactory.close( );
}
}

0 个答案:

没有答案