3

I am trying to run integration test with spring boot and get the following error:

Caused by: org.springframework.context.ApplicationContextException:
Failed to start bean 'SchedulerFactory'; nested exception is org.springframework.scheduling.SchedulingException:
Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: 
Failure occured during job recovery. [See nested exception:
org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: Table "QRTZ_LOCKS" not found; SQL statement:
SELECT * FROM QRTZ_LOCKS UPDLOCK WHERE LOCK_NAME = ? [42102-193] [See nested exception: org.h2.jdbc.JdbcSQLException: Table "QRTZ_LOCKS" not found; SQL statement:
SELECT * FROM QRTZ_LOCKS UPDLOCK WHERE LOCK_NAME = ? [42102-193]]]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)

It is clear that QRTZ tables were not created. I can create them manually, but is it true that spring boot is not able to create them when they are not exists? Looks very strage if so, because these tables needs to be created only once at start up and sql statements like create if not exisit is enough. So can spring boot automatically creates QRTZ tables?

Cherry
  • 31,309
  • 66
  • 224
  • 364
  • The error message says that there is no table named QRTZ_LOCKS. You say "`QRTZ` tables were not created"; do you mean that there is code to create the QRTZ_LOCKS table before the code that threw this exception? – arcy Feb 19 '17 at 13:13
  • `there is a code to create...` Yes, The question is about that. Does that code exist or not? – Cherry Feb 19 '17 at 13:43

1 Answers1

5

No, spring boot does not automatically create quartz tables. If you want create that automatically, you need to use the Datasource Initializer feature of Spring Boot which will create the tables automatically for you.

As you already know Spring boot hands down a great framework, saving the developer a lot of time and energy when developing a spring application. One of its great features is database initialization. You can use spring boot in order to initialize your sql database.

org.springframework:spring-jdbc dependency is the dependency that assists with the database initialization.

You just need to add a schema.sql file to the resource folder so it would be loaded to classpath. The schema.sql file would contain all the table definitions needed for our database, here quartz schema (find this inside quartz distribution). Next file to add is data.sql on the resources folder. This file will contain the sql statements needed to populate our database. Ignore this for quartz.

On initialization spring boot will search for the schema.sql and data.sql files and execute them with the Database initializer.

Monzurul Shimul
  • 8,132
  • 2
  • 28
  • 42