init.sql
This commit is contained in:
parent
7e8f103438
commit
e1f1c06b59
|
@ -5,8 +5,11 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
|
@ -76,4 +79,17 @@ public class JdbcConfiguration implements TransactionManagementConfigurer {
|
|||
public EntityManager entityManager() {
|
||||
return entityManagerFactory().getObject().createEntityManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
|
||||
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
|
||||
databasePopulator.addScript(new ClassPathResource("/init.sql"));
|
||||
databasePopulator.setIgnoreFailedDrops(true);
|
||||
|
||||
DataSourceInitializer initializer = new DataSourceInitializer();
|
||||
initializer.setDataSource(dataSource);
|
||||
initializer.setDatabasePopulator(databasePopulator);
|
||||
|
||||
return initializer;
|
||||
}
|
||||
}
|
||||
|
|
1
src/main/resources/init.sql
Normal file
1
src/main/resources/init.sql
Normal file
|
@ -0,0 +1 @@
|
|||
--insert into meta_member_status (id, name) values (7, 'FFFFF');
|
Loading…
Reference in New Issue
Block a user