spring boot整合quartz框架,存储到mysql数据库

2025-04-05 12:01:05

1、利用intellij idea创建java maven项目

spring boot整合quartz框架,存储到mysql数据库

2、添加如下重要依赖spring-boot-starter-孥恶膈茯quartz<!-- https://mvnrepository.co罪焐芡拂m/artifact/org.springframework.boot/spring-boot-starter-quartz --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-quartz</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency>

spring boot整合quartz框架,存储到mysql数据库

3、整个pom配置文件如下图所示

spring boot整合quartz框架,存储到mysql数据库

4、在application.yml配置文件,添加数据源配置,quartz相关配置,如下图所示logging: level: root: debugspring: datasource: druid: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/quartz?serverTimezone=Hongkong&characterEncoding=utf8&useUnicode=true&useSSL=false&allowMultiQueries=true username: root password: 123456 initialSize: 5 minIdle: 50 maxActive: 500 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 filters: stat,wall,log4j connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 useGlobalDataSourceStat: true quartz: job-store-type: jdbc

spring boot整合quartz框架,存储到mysql数据库

5、打开源码,找到org/quartz/impl/jdbcjobstore/tables_mysql_innodb.sql,复制sql语句,初始化数据库表

spring boot整合quartz框架,存储到mysql数据库

6、如果要在job实现类中,注入spring的其他单例,可以使用@Component注解。然后就可以根据quartz的文档开发,JobBuilder.newJob(jobClass),底层会找到刚才主导到spring容器的job类

spring boot整合quartz框架,存储到mysql数据库
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:84
  • 阅读量:62
  • 阅读量:41
  • 阅读量:91
  • 阅读量:48
  • 猜你喜欢