spring 初始化SQL脚本

@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

PS:如果您想和业内技术大牛交流的话,请加qq群(527933790)或者关注微信公众 号(AskHarries),谢谢!

转载请注明原文出处:Harries Blog™ » spring 初始化SQL脚本

赞 (0)

分享到:更多 ()

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址