EclipseLinke:没有名为META-INF / services / javax.persistence.spi的资源文件:找不到PersistenceProvider [英] EclipseLinke:No resource files named META-INF/services/javax.persistence.spi:No PersistenceProvider were found

查看:1090
本文介绍了EclipseLinke:没有名为META-INF / services / javax.persistence.spi的资源文件:找不到PersistenceProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EclipseLink,甚至我已经使用maven导入了所有必需的jar文件,我仍然得到例外:

I am using EclipseLink and even I have all necessary jar files imported with maven, I get still the Exception:


线程中的异常mainjavax.persistence.PersistenceException:没有名为

资源文件META-INF / services / javax.persistence.spi.PersistenceProvider找到
。请确保持久性提供程序jar文件在
类路径中。

Exception in thread "main" javax.persistence.PersistenceException: No resource files named META-INF/services/javax.persistence.spi.PersistenceProvider were found. Please make sure that the persistence provider jar file is in your classpath.

在Maven pom中我有依赖关系:

In Maven pom I have the dependency:

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

这是我的persistence.xml:

Here is my 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="PersistenzJPAProjekt">
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.testJPABasis.Person</class>

    </persistence-unit>
</persistence>

这里是eclipse中的clathpath:

Here the clathpath in eclipse:

实际生成异常的类:

public class TestJPA
{
    public static void main(String[] args)
    {
        Person person = new Person();
        person.setPersonID(1);

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersistenzJPAProjekt");
        EntityManager em = emf.createEntityManager();

    }
}

persistence.xml直接位于META-INF。据我所知,我不需要Glassfish或Tomcat,因为EclipseLink是为独立应用程序而制作的。如果我错了,也许这就是原因。 Meta-Inf位于:

The persistence.xml is directly under META-INF. As far as I know I don't need to have Glassfish or Tomcat as EclipseLink is made for standalone applications. If I am wrong maybe this is then the cause. The Meta-Inf is placed in:

推荐答案

persistence-api 就是这样的:API (主要是接口)。您仍然需要包含实际的持久性提供程序;看起来你想要EclipseLink。

persistence-api is just that: the API (mostly interfaces). You still need to include the actual persistence provider; it looks like you're wanting EclipseLink.

这篇关于EclipseLinke:没有名为META-INF / services / javax.persistence.spi的资源文件:找不到PersistenceProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆