spring 多数据源下如何初始化 H2 数据库?

2021-08-16 14:52:06 +08:00
 shadowfish0

原来项目是单数据源的,用 H2 内存数据库做测试用,可以直接用 spring 提供的 schema 、data 配置来自动初始化,但是用了多数据源之后这两个参数的解析一直有问题,遂弃用,转而想要实现每个测试 BeforeAll 时执行初始化 SQL,但是又一直报 server time zone 异常: org.springframework.jdbc.datasource.init.UncategorizedScriptException: Failed to execute database script; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specific time zone value if you want to utilize time zone support. 然后上网查询到 H2 不支持设置 serverTimezone,我尝试 System.setProperty("user.timezone", "GMT")也依然无效,现在实在是没有办法了...

475 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/796068

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX