【发布时间】:2019-03-19 22:02:03
【问题描述】:
当我运行单元测试时出现这两个错误
org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve 信息:HHH000318:在类路径中找不到任何 META-INF/persistence.xml 文件
和
javax.persistence.PersistenceException:没有名为 dbContext 的 EntityManager 的持久性提供程序
我没有同时理解它们,因为正如您在图片 en persistence.xml 文件中看到的那样,该文本下方的所有内容都是他所抱怨的。
这里有我的persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="dbContext">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="{urltodb}"/>
<property name="hibernate.connection.autocommit" value="false"/>
<property name="hibernate.connection.username" value="{myusername}"/>
<property name="hibernate.connection.password" value="{mypassword}"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.connection.CharSet" value="utf8"/>
<property name="hibernate.connection.characterEncoding" value="utf8"/>
<property name="hibernate.connection.useUnicode" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
【问题讨论】:
-
不应该在
src/main/resources/META-INF吗? -
是的。 Intellij 只是显示不同,我不知道为什么。但是当我将鼠标悬停在持久性文件上时,它指出它在 scr/main/resources/META-INF