Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring @sqlgroup with multiple datasource

Tags:

spring-test

I am trying to use @sql and @sqlgroup on my unit test but I want this annotation to use datasource with different name other than default datasource.

How can you achieve this?

like image 820
user509755 Avatar asked Feb 11 '23 07:02

user509755


1 Answers

From the Transaction management for @Sql section of the Spring Reference Manual:

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.

For example:

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

Regards,

Sam (author of the Spring TestContext Framework)

like image 119
Sam Brannen Avatar answered Feb 12 '23 20:02

Sam Brannen