我Spring-Boot用于的应用程序hibernate.hbm2ddl.=update。
Spring-Boot
hibernate.hbm2ddl.=update
如何确保启动时执行sql脚本?因此,我想确保at FUNCTION .. LANGUAGE plpgsql在我的postgresql数据库中。
FUNCTION .. LANGUAGE plpgsql
postgresql
通过使用 XML 。
<jdbc:initialize-database data-source="dataSource"> <jdbc:script location="classpath:com/foo/sql/db-schema.sql"/> <jdbc:script location="classpath:com/foo/sql/db-test-data.sql"/> </jdbc:initialize-database>
通过使用 注释 (下面的示例应该放在您的@Configuration类中)
@Configuration
@Value("classpath:com/foo/sql/db-schema.sql") private Resource schemaScript; @Value("classpath:com/foo/sql/db-test-data.sql") private Resource dataScript; @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.addScript(schemaScript); populator.addScript(dataScript); return populator; }