【发布时间】:2018-07-31 09:13:18
【问题描述】:
我有一个 SpringBoot 2.0 应用程序,我决定使用 orm.xml 混合注释和 XML 配置。所以,我把orm.xml(带有XML配置的JPA文件)放在resources/META-INF中,在启动应用程序时,它被考虑在内,一切都很好,它就像一个魅力。
但是,在运行集成测试(使用内存数据库)时,orm.xml 似乎被完全忽略了,因为测试失败并出现与缺少映射相关的异常,我在@987654326 中编写了映射@(一个可嵌入的实体)。
这是一个测试的样子:
package hello;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@DataJpaTest
public class ApplicationTests {
@Test
public void contextLoads() {
}
}
我也试过@AutoConfigureTestDatabase而不是@DataJpaTest,但没有成功。
为了让集成测试加载orm.xml,我应该改变什么?
【问题讨论】:
-
它在
persistence.xml中吗?还是“标准” Spring 使用的任何借口?
标签: spring jpa spring-boot spring-boot-test