POM文件添加Quartz依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-quartz</artifactId>
</dependency>

application.yml配置Quartz

spring:
  #定时框架
  quartz:
    #任务存储方式
    job-store-type: jdbc
    jdbc:
      #初始化表结构
      initialize-schema: always
    #定时名称
    scheduler-name: task
    #配置自定义数据源
    datasource:
      type: com.alibaba.druid.pool.DruidDataSource
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://192.168.199.157:3306/quartz?serverTimezone=GMT%2B8
      username: root
      password: 123654ocalhost:3306/quartz?serverTimezone=GMT%2B8
          username: root
          password: 123654

创建DataSourceConfig配置类

/**
 * 数据源配置
 */
@Configuration
public class DataSourceConfig {

    /**
     * 默认数据源
     *
     * @return 数据源
     */
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean(name = "druidDataSource")
    public DataSource druidDataSource() {
        return new DruidDataSource();
    }

    /**
     * quartz专用数据源
     *
     * @return 数据源
     */
    @ConfigurationProperties(prefix = "spring.quartz.datasource")
    @QuartzDataSource
    @Bean(name = "quartzDataSource")
    public DataSource quartzDataSource() {
        return new DruidDataSource();
    }
}