spring使用DataSourceInitializer执行数据库初始化脚本

@Bean
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
    final DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);
    initializer.setDatabasePopulator(databasePopulator());
    return initializer;
}

private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScripts(new ClassPathResource("/mysql.ddl"));
    return populator;
}

posted on 2022-04-11 22:38  路过君  阅读(166)  评论(0编辑  收藏  举报

导航