spring @sqlgroup 有多个数据源

spring @sqlgroup with multiple datasource

我正在尝试在我的单元测试中使用@sql 和@sqlgroup,但我希望此注释使用与默认数据源不同的名称的数据源。

你如何做到这一点?

来自 Spring 参考手册的 Transaction management for @Sql 部分:

If the algorithms used by SqlScriptsTestExecutionListener to detect a DataSource and PlatformTransactionManager and infer the transaction semantics do not suit your needs, you may specify explicit names via the dataSource and transactionManager attributes of @SqlConfig.

例如:

@SqlGroup({
    @Sql(scripts = "script1.sql", config = @SqlConfig(dataSource = "dataSource1", transactionManager = "txMgr1")),
    @Sql(scripts = "script2.sql", config = @SqlConfig(dataSource = "dataSource2", transactionManager = "txMgr2"))
})

此致,

Sam(Spring TestContext Framework 的作者)