grails-spring-batch
grails-spring-batch copied to clipboard
Error when loading tables for Postgresql
If the database type is not specified as 'postgres' (i.e. you specify postgresql
as per the documentation) then you get an exception:
Error Error running forked test-app: Error creating bean with name 'jobOperator': Cannot resolve reference to bean 'jobRepository' while setting bean property 'jobRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'postgresql' is an unsupported database type. The supported database types are DERBY,DB2,DB2ZOS,HSQL,SQLSERVER,MYSQL,ORACLE,POSTGRES,SYBASE,H2,SQLITE
So you need to do this:
plugin { springBatch { jmx { enable = false } loadTables = true database = 'postgres' } }
However, this means that loadtables looks for the wrongly named scripts (the missing "ql" is important!):
// within SpringBatchGrailsPlugin.groovy doWithApplicationContext def script = "org/springframework/batch/core/schema-drop-${database}.sql" script = "org/springframework/batch/core/schema-${database}.sql"
Work around for this: I use the Grails Database Migration Plugin.
Future Fix, introduce a translation function to convert the database type above into the String necessary to load the schema from the file.
@danieldbower Sorry, I don't understand your workaround - I take it you specify postgres
in order to not get the exception details above, but then how does the Migration Plugin help with the error in the script?
So, instead of letting the Spring Batch Plugin populate the database schema, I manually add it to the data migration.