Polish "Add Quartz Scheduler support"

Closes gh-4299
This commit is contained in:
Stephane Nicoll
2017-05-30 18:32:59 +02:00
parent 9e23206c31
commit 59a15b259c
12 changed files with 315 additions and 124 deletions

View File

@@ -130,9 +130,10 @@ content into your application; rather pick only the properties that you need.
spring.profiles.include= # Unconditionally activate the specified comma separated profiles (or list of profiles if using YAML).
# QUARTZ SCHEDULER ({sc-spring-boot-autoconfigure}/quartz/QuartzProperties.{sc-ext}[QuartzProperties])
spring.quartz.initializer.enabled=true # Create the required Quartz Scheduler tables on startup if necessary. Enabled automatically if the schema is configured.
spring.quartz.job-store-type=memory # Quartz job store type.
spring.quartz.properties.*= # Additional Quartz Scheduler properties.
spring.quartz.schema=classpath:org/quartz/impl/jdbcjobstore/tables_@@platform@@.sql # Path to the SQL file to use to initialize the database schema.
spring.quartz.jdbc.initialize-schema=false # Create the required Quartz Scheduler tables on startup.
spring.quartz.jdbc.schema=classpath:org/quartz/impl/jdbcjobstore/tables_@@platform@@.sql # Path to the SQL file to use to initialize the database schema.
# Reactor
spring.reactor.stacktrace-mode.enabled=false # Set whether Reactor should collect stacktrace information at runtime.

View File

@@ -5153,32 +5153,66 @@ caching is enabled.
[[boot-features-quartz]]
== Quartz Scheduler
Spring Boot offers several conveniences for working with the Quartz scheduler, including
the `spring-boot-starter-quartz` '`Starter`'. If Quartz is available, a `Scheduler` will
be auto-configured (via the `SchedulerFactoryBean` abstraction).
If Quartz Scheduler and the relevant libraries (as defined by `spring-boot-starter-quartz`)
are on the classpath, Spring Boot will auto-configure a `SchedulerFactoryBean` which
provides `Scheduler` instance that you can inject in your application.
Beans of the following types will be automatically picked up and associated with the
the `Scheduler`:
Beans of following types will be automatically picked up and added to
`SchedulerFactoryBean`:
* `JobDetail`
* `JobDetail`: defines a particular Job. `JobDetail` instance can easily be built with
the `JobBuilder` API
* `Calendar`
* `Trigger`
* `Trigger`: defines when a particular job is triggered
By default, an in-memory `JobStore` will be used. However, if `DataSource` bean is
available in your application, Quartz Scheduler will be configured with a persistent
`JobStore`.
By default, an in-memory `JobStore` will be used. However, it is possible to configure
a JDBC-based store if a `DataSource` bean is available in your application and if the
`spring.quartz.job-store-type` property is configured accordingly:
When using a persistent `JobStore`, Quartz database schema can be initialized using
`QuartzDatabaseInitializer` if the location of schema script is configured using
`spring.quartz.schema` property.
[source,properties,indent=0]
----
spring.quartz.job-store-type=jdbc
----
Quartz Scheduler configuration can also be customized using Quartz configuration properties
(see `spring.quartz.properties.*`) and `SchedulerFactoryBeanCustomizer` beans which
allows programmatic `SchedulerFactoryBean` customization.
When the jdbc store is used, the schema can be initialized on startup:
Spring Boot also configures `JobFactory` that is `@Autowire` capable so you can easily
inject beans from `applicationContext` and use them in your Quartz jobs.
[source,properties,indent=0]
----
spring.quartz.jdbc.initialize-schema=true
----
NOTE: The database is detected by default and initialized using the standard scripts
provided with the Quartz library. It is also possible to provide a custom script using the
`spring.quartz.jdbc.schema` property.
Quartz Scheduler configuration can be customized using Quartz configuration properties (see
`spring.quartz.properties.*`) and `SchedulerFactoryBeanCustomizer` beans which allows
programmatic `SchedulerFactoryBean` customization.
Job can define setters to inject data map properties. Regular beans can also be injected
in a similar manner:
[source,java,indent=0]
----
public class SampleJob extends QuartzJobBean {
private MyService myService;
private String name;
// Inject "MyService" bean
public void setMyService(MyService myService) { ... }
// Inject the "name" job data property
public void setName(String name) { ... }
@Override
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
...
}
}
----