> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/39.-quartz-scheduler.md).

# 39. Quartz调度器

Spring Boot包含有`spring-boot-starter-quartz`Starter，方便了使用[Quartz调度器](http://www.quartz-scheduler.org/)。如果Quartz可用，调度器会被自动配置（通过SchedulerFactoryBean抽象）。

以下类型的bean会被自动捡起并关联到调度器：

* `JobDetail`:定义一个特别的Job。`JobDetail`实例能够容易地用`JobBuilder`API创建
* `Calendar`
* `Trigger`:定义何时一个特别的Job被触发

默认的，一个内存中`JobStore`会被使用。但是，配置一个基于JDBC的store是可能的。如果在你的应用中`DataSource`bean可用，而且`spring.quartz.job-store-type`属性如下配置：

```
spring.quartz.job-store-type=jdbc
```

当jdbc store被使用,模式能够在启动时被初始化：

```
spring.quartz.jdbc.initialize-schema=always
```

**注** 数据库会默认被检查，而且会被初始化（使用由Quartz库提供的标准脚本）。也可以使用`spring.quartz.jdbc.schema`属性提供一个自定义脚本。

Quartz调度器的配置能够使用Quartz配置属性（查看`spring.quartz.properties.*`），和`SchedulerFactoryBeanCustomizer`bean（允许程序化的`SchedulerFactoryBean`配置）来自定义 。

Job能够定义setter来注入数据映射属性。普通的bean也能够用相似的行为来注入：

```java
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 {
        ...
    }

}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/39.-quartz-scheduler.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
