問題描述
我正在嘗試在 Maven 構建期間將測試數據加載到測試數據庫中以進行集成測試.persistence.xml 被正確復制到 target/test-classes/META-INF/
,但是在運行測試時出現此異常.
I'm trying to load test data into a test DB during a maven build for integration testing. persistence.xml is being copied to target/test-classes/META-INF/
correctly, but I get this exception when the test is run.
javax.persistence.PersistenceException:沒有持久性提供程序EntityManager 命名為目標數據庫
javax.persistence.PersistenceException: No Persistence provider for EntityManager named aimDatabase
它似乎沒有找到或加載persistence.xml.
It looks like it's not finding or loading persistence.xml.
推薦答案
剛剛用一個基于 Maven/Eclipse 的 JPA 項目解決了同樣的問題.
Just solved the same problem with a Maven/Eclipse based JPA project.
我的 META-INF 目錄位于 src/main/java
下,因為在測試階段之前它沒有復制到目標目錄.
I had my META-INF directory under src/main/java
with the concequence that it was not copied to the target directory before the test phase.
將此目錄移動到 src/main/resources
解決了問題,并確保 META-INF/persistence.xml
文件存在于 target/classes
運行測試的時間.
Moving this directory to src/main/resources
solved the problem and ensured that the META-INF/persistence.xml
file was present in target/classes
when the tests were run.
我認為 JPA 方面將我的 META-INF/persistence.xml
文件放在 src/main/java
中,結果證明成為我問題的根源.
I think that the JPA facet put my META-INF/persistence.xml
file in src/main/java
, which turned out to be the root of my problem.
這篇關于在 Maven 測試期間未找到 persistence.xml的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!