我从来没有让它工作。如果您只想要开发数据的快照(启动时加载),我发现使用 DBUnit 导出/导入数据对我来说非常有用。我写了一个脚本来导出它,我从控制台调用它:
class DataExport {
def ctx = SCH.servletContext.getAttribute(GA.APPLICATION_CONTEXT)
def exportData() {
println "-->export"
def ds = ctx.dataSourceUnproxied
println ds.dump()
Connection jdbcConnection = ctx.dataSourceUnproxied.getConnection()
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
println connection.dump()
ITableFilter filter = new DatabaseSequenceFilter(connection);
IDataSet dataset = new FilteredDataSet(filter, connection.createDataSet());
FlatXmlDataSet.write(dataset, new File("full.xml").newWriter());
connection.close()
}
}
然后在引导程序中,您可以将其重新加载
Connection jdbcConnection
FlatXmlDataSet dataSet = new FlatXmlDataSetBuilder().build(new ClassPathResource('resources/data/full.xml').inputStream)
jdbcConnection = ctx.dataSource.getConnection()
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
try {
DatabaseOperation.INSERT.execute(connection, dataSet)
} catch(e) {
e.printStackTrace()
throw(e)
} finally {
jdbcConnection.close()
}
log.info 'data loaded'