@Bean
@Profile({ "dev", "test", "prod" })
public InitializingBean sqlScriptInitAll() {
List<ClassPathResource> scriptList = null;
// 创建存储过程
try {
scriptList = new ArrayList<>();
sanfSqlFile(scriptList);
} catch (Exception e) {
e.printStackTrace();
}
if (vnelDataInit != null && vnelDataInit.booleanValue()) {
return dataSourceInitializer(scriptList);
}
return null;
}
// --------------------------------------------------------------------------------
private DataSourceInitializer dataSourceInitializer(List<ClassPathResource> scriptList) {
if (scriptList.size() <= 0) {
return null;
}
ClassPathResource[] resArray = new ClassPathResource[scriptList.size()];
resArray = scriptList.toArray(resArray);
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(true, true, "utf-8", resArray);
DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(dataSource);
initializer.setDatabasePopulator(databasePopulator);
initializer.setEnabled(true);
LOGGER.info("初始化SQL成功!");
return initializer;
}
原文
http://www.zzcode.cn/spring/thread-527.html