java - datajptest + springframework 测试Sql编码特殊字符在Windows上失败
问题描述
在 Windows (+ Maven) 上,我é
对Métro
单词有疑问。我的 sql 文件以 UTF-8 编码。我在 Unix 服务器上确实有这个问题。
我的 Maven 错误:
expected:<M[é]tro Ligne 6, station...> but was:<M[é]tro Ligne 6, station...>
我的 JUnit 代码:
@RunWith(SpringRunner.class)
@DataJpaTest
@ActiveProfiles("test")
public class MyRepositoryTest {
@Autowired
private MyRepository myRepository;
@Test
@Sql("/data/myRepositoryTest.sql")
public void testFindById() {
Optional<My> my= myRepository.findById(99999);
assertTrue(my.isPresent());
assertEquals("Métro Ligne 6, station Bel-Air", my.get().getItinerary());
}
}
我的 sql 文件:
INSERT INTO MY(ID, NAME, CODE, ITINERARY)
VALUES (99999, 'foo', 'abc', 'Métro Ligne 6, station Bel-Air');
解决方案
The default encoding is taken from the operation system, hence the problem.
Set the SQL file encoding like this:
@Sql(value = "/data/myRepositoryTest.sql", config = @SqlConfig(encoding = "utf-8"))
推荐阅读
- python - 如何修复错误“错误:命令错误退出状态 1:python。” 尝试安装 FOMMRIA 时
- php - 当 Google App Engine 项目的根文件夹在 composer.json 目录之外时,如何安装 composer 依赖项?
- laravel - 在 Laravel 中从 env->config->blade 加载常量的行为不稳定的原因是什么?
- python - 不支持查找 CharField 的“product_name”或不允许加入该字段。Django Python ORM
- java - 在 Kotlin 的 JPA 存储库上调用 save 时局部变量类型错误
- python - 使用 selenium 从动态网页表中查找值
- javascript - 在 Django 中使用 gltf 加载器加载三个 JS 模型
- flutter - 设置手势栏颜色透明[Flutter]
- javascript - 如何使用一个集合中的文档字段从不同集合中检索另一个文档字段?
- php - 在另一个类中使用类时找不到 PHP 类