且构网

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

在没有XML配置的情况下初始化数据库,但使用@Configuration

更新时间:2022-11-03 09:34:08

在查看与EmbeddedDatabaseBuilder相关的Spring类之后,我发现DatabaseBuilder正在使用一些看起来像这样的代码:

After looking at Spring classes related to EmbeddedDatabaseBuilder I found out that the DatabaseBuilder is using some code looking like this:

ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
for (String sqlScript: sqlInitializationScripts ) {
  Resource sqlScriptResource = RESOURCE_LOADER.getResource(sqlScript);
  populator.addScript(sqlScriptResource);
}
DatabasePopulatorUtils.execute(populator, dataSource);

这对我来说很好,即使它是@BeforeTest方法而不是Spring配置。

This will work fine for me, even if it will be on a @BeforeTest method and not on the Spring configuration.