且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Spring和jdbc DataSourceTransactionManager填充H2数据库

更新时间:2023-01-18 16:10:47

自从我使用事务以来,它就与脚本执行冲突以创建表和加载数据.

Since I was using transactions it was ***ing with execution of scripts to create tables and load data.

这些脚本需要在不执行spring config添加的事务语义的情况下在外部执行.

These scripts need to be executed outside without applying transaction semantics added by spring config.

因此,我如下更改嵌入式数据库Bean以删除脚本元素:

So I changed embedded database bean as follows to remove script elements:

<jdbc:embedded-database id="embeddedH2Database" type="H2"/>

在测试之前添加@Sql注释以创建表和加载表.

And added @Sql annotation before my test to create table and load table.

@Sql({"classpath:db/sql/create-db.sql", "classpath:db/sql/insert-data.sql"})