我们有一个关于 spring-boot 版本 1.5.2.RELEASE 的项目。
我们需要在 xml 中处理 hibernate 命名查询(java 注释中的命名查询不是我们的选择)。
为此,我们hbm.xml
在目录中添加了所有文件(包含这些命名查询)src/main/resources
。
当我们的应用程序运行时,这不是问题。命名查询被正确提取。
但是,当我们编写集成测试用例时,它无法识别命名查询。
我们得到:
未找到命名查询异常
下面是我们的测试用例代码:
@RunWith(SpringRunner.class)
@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MyIntegrationTest {
@Autowired
private TestRestTemplate template;
@Test
public void checkRestService() throws Exception {
ResponseEntity<String> response = template.getForEntity("/hello/1", String.class);
assertTrue(response.getStatusCodeValue() == 200);
}
}
如果我们将hbm.xml
文件复制到 中src/test/resources directory
,则hbm.xml
文件会被正确拾取并且测试会正确运行。
无论如何,xml文件是直接从src/main/resouces
文件夹中提取的,我们不必复制这些文件吗?