1.Mybatis相关
mybatisSpringTests
- Caused by: java.io.FileNotFoundException: class path resource [truncate.sql] cannot be opened because it does not exist(@Sql 注解中 文件不存在)
原因分析:文件不存在一般有两种原因:1.单词拼写错误,2.Sql脚本文件路径放置错误导致Spring访问不到
代码:
@SpringJUnitConfig(SpringConfig.class)
public class MybatisSpringTests {
@Autowired
AdminMapper adminMapper;
@Test
@Sql(scripts = {"classpath:truncate.sql","classpath:insert_data.sql"})
@Sql(scripts = {"classpath:truncate.sql"},executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testDeleteByIdSuccessfully(){
Long id = 1L;
int rows= adminMapper.deleteById(id);
Assertions.assertEquals(1,rows);
}
}
纠错:1.单词没有拼写错误,2.尝试修改Sql脚本文件的位置
真正原因是:需要将.sql脚本文件所在的resources目录放置在test的目录下 与../test/java目录同级