【问题标题】:datajpatest + springframework test Sql encoding special characters fail on Windowsdatajptest + springframework 测试Sql编码特殊字符在Windows上失败
【发布时间】:2019-03-13 07:50:47
【问题描述】:

在 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');

【问题讨论】:

  • 什么是数据库类型?你在哪一行得到错误?

标签: java maven jpa testing junit


【解决方案1】:

默认编码取自操作系统,因此存在问题。

像这样设置 SQL 文件编码:

@Sql(value = "/data/myRepositoryTest.sql", config = @SqlConfig(encoding = "utf-8"))

【讨论】:

    猜你喜欢
    • 2020-02-17
    • 2021-02-04
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    相关资源
    最近更新 更多