Wednesday, October 1, 2008

Setting up Quartz in a Spring-MySQL Environment

If you are using a persistent JobStore in Quartz, you will have to back your spring application with a DB. MySQL can be pretty convenient for local unit testing. Besides the regular spring DataSource config, you need a few more things here and there. I did not find any comprehensive "todo" checklist for MySQL online. So summing up what worked for me.

Using SchedularFactoryBean you can specify a MySQL DataSource and fine-tune it using quartz properties. You can see this in a config file I had published earlier:

XML Config

Besides this, you need to have the following dependencies for sure in your pom if you are using Maven:

POM dependencies

If you are not using maven, the corresponding jars should be in the classpath.

Finally, don't forget to run the SQL script to create tables in your database provided by quartz:

Creating DB Tables for Quartz

1 comment:

Nick Spacek said...

This is an old post, but a top in the Google results for "quartz mysql".

All the properties related to the datasource under quartzProperties aren't required if you are already specifying the dataSource property and referencing the dataSource bean.

So:
...
  <property name="dataSource" ref="dataSource"/>
...

and:

<bean id="dataSource"
    class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
  <property name="url" value="jdbc:mysql://huygens/quartz"/>
  <property name="user" value="quartz"/>
  <property name="password" value="quartz"/>
</bean>