I just created a batch job using Spring Batch framework, but I don\'t have Database privileges to run CREATE SQL. When I try to run the batch job I hit the error while the f
Spring Batch uses the database to save metadata for its recover/retry functionality.
If you can't create tables in the database then you have to disable this behaviour
If you can create the batch metadata tables but not in runtime then you might create them manually
To enable auto create spring batch data-schema simply add this line to your spring application.properties file :
spring.batch.initialize-schema=always
To understand more about Spring batch meta-data schema :
https://docs.spring.io/spring-batch/trunk/reference/html/metaDataSchema.html
With Spring Boot 2.0 you probably need this: https://docs.spring.io/spring-boot/docs/2.0.0.M7/reference/htmlsingle/#howto-initialize-a-spring-batch-database
spring.batch.initialize-schema=always
By default it will only create the tables if you are using an embedded database.
Or
spring.batch.initialize-schema=never
To permanently disable it.
<jdbc:initialize-database/>
tag is parsed by Spring using InitializeDatabaseBeanDefinitionParser
. You can try debugging this class in your IDE to make sure what values are being picked up for enabled
attribute. Also this value can be disabled by using JVM parameter -Dspring.batch.initializer.enabled=false
Spring Batch required following tables to run job
If you are using h2 db then it will create all required table by default
When you start using Mysql or any other database you need to add follwing properties into application.properties
spring.batch.initialize-schema=always
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd">
<!-- database -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/springbatch" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<!-- transaction manager -->
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<!-- create job-meta tables automatically -->
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="org/springframework/batch/core/schema-drop-mysql.sql" />
<jdbc:script location="org/springframework/batch/core/schema-mysql.sql" />
</jdbc:initialize-database>
</beans>
And make sure you are using compatible spring-jdbc -version with spring-batch. Most probably spring-jdbc-3.2.2.RELEASE.JAR compatible.