# scheduled-task-spring-boot-starter
基于Zookeeper的最最轻量级的分布式定时任务,一个Start就搞定!!! 封装的**elastic-job-lite** & **elastic-job-lite-console**.
+ 支持手动触发Job
+ 支持手动添加Job
+ 支持一次性Job
+ 查看Job以及服务器状态
+ 快捷的修改以及删除Job设置
+ 启用和禁用Job
+ 跨注册中心查看Job
+ 查看Job运行轨迹和运行状态
> **💡提示:** 初始代码Copy自:`number68/scheduled-task`
## 依赖引入
### 通过Maven的`pom.xml`引入。
```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.wjw.job</groupId>
<artifactId>testscheduledtask</artifactId>
<version>1.0.0</version>
<name>TestScheduledTask</name>
<description>test scheduledtask</description>
<properties>
<java.version>1.8</java.version>
<elastic-job.version>2.1.5</elastic-job.version>
<mysql.version>5.1.49</mysql.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.github.wjw465150</groupId>
<artifactId>scheduled-task-spring-boot-starter</artifactId>
<version>2.1.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
```
### 或者通过Gradle的`build.gradle`引入
```groovy
plugins {
id 'org.springframework.boot' version '2.4.12'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
// jar包的名字
archivesBaseName = 'scheduled-task-test'
ext {
mysql = [version : '5.1.49']
elasticjob = [version : '2.1.5']
}
group = 'org.wjw.starter.test'
version = '1.0.0'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
mavenLocal()
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } //优先使用阿里的镜像
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
runtimeOnly "mysql:mysql-connector-java:${mysql.version}"
implementation group: 'com.github.wjw465150', name: 'scheduled-task-spring-boot-starter', version: '2.1.8'
}
```
## 编写SpringBoot的启动类
```java
package TestScheduledTask
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@SpringBootApplication
public class ScheduledTaskApplication {
private static final Logger log = LoggerFactory.getLogger(ScheduledTaskApplication.class);
public static void main(String[] args) {
SpringApplication.run(ScheduledTaskApplication.class, args);
log.info("------------scheduled-task started successfully-------------");
}
}
```
## 编写一个SimpleJob类来测试:
```java
package TestScheduledTask.job;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cloud.task.annotation.ScheduledTask;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
/**
* SimpleJob类型的的例子
* @author White Stone
*
* 2021年12月14日
*/
@ScheduledTask(name = "SimpleJobExample", cron = "0/30 * * * * ?", shardingTotalCount = 3, shardingItemParameters="0=Beijing,1=Shanghai,2=Guangzhou", overwrite = true)
public class SimpleJobExample implements SimpleJob {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public void execute(ShardingContext shardingContext) {
//打印出任务相关信息,JobParameter用于传递任务的ID
logger.info("JobName:{}, ShardingTotalCount:{}, JobParameter={}, ShardingItem: {}, ShardingParameter: {}",
shardingContext.getJobName(),
shardingContext.getShardingTotalCount(),
shardingContext.getJobParameter(),
shardingContext.getShardingItem(),
shardingContext.getShardingParameter()
);
}
}
```
## 编写application配置文件`application.yml`
```yaml
spring:
application:
name: scheduled-task
server:
port: 8090
logging:
level:
root: info
---
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/scheduled-task?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&characterEncoding=UTF-8
username: root
password: 11111111
hikari:
minimum-idle: 5
maximum-pool-size: 10
#控制台认证
auth:
username: admin
password: 123456
#连接到zookeeper的配置
zookeeper:
serviceLists: 127.0.0.1:2181
namespace: scheduled-task
baseSleepTimeMilliseconds: 5000
maxSleepTimeMilliseconds: 5000
maxRetries: 3
scheduledTask:
#定时任务监控预警
monitor:
enable: true
time:
interval: 3
```
## 启动:
运行启动类`ScheduledTaskApplication`启动项目
输出如下:
```bash
!!!!!!=================Spring DefaultProfiles:[default]=================!!!!!!
!!!!!!=================Spring ActiveProfiles:[dev]=================!!!!!!
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.12)
2021-12-14 20:09:11.519 [main] INFO TestScheduledTask.TestApplication - [logStarting,55] - Starting TestApplication using Java 1.8.0_301 on WJW-T14 with PID 21332 (C:\WJW_Z\eclipse_scheduled-task\scheduled-task\scheduled-task-test\bin\main started by 86189 in C:\WJW_Z\eclipse_scheduled-task\scheduled-task\scheduled-task-test)
2021-12-14 20:09:11.522 [main] INFO TestScheduledTask.TestApplication - [logStartupProfileInfo,668] - The following profiles are active: dev
2021-12-14 20:09:12.421 [main] INFO o.s.boot.web.embedded.tomcat.TomcatWebServer - [initialize,108] - Tomcat initialized with port(s): 8090 (http)
2021-12-14 20:09:12.431 [main] INFO org.apache.coyote.http11.Http11NioProtocol - [log,173] - Initializing ProtocolHandler ["http-nio-8090"]
2021-12-14 20:09:12.431 [main] INFO org.apache.catalina.core.StandardService - [log,173] - Starting service [Tomcat]
2021-12-14 20:09:12.431 [main] INFO org.apache.catalina.core.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/9.0.54]
2021-12-14 20:09:12.502 [main] INFO o.a.c.core.ContainerBase.[Tomcat].[localhost].[/] - [log,173] - Initializing Spring embedded WebApplicationContext
2021-12-14 20:09:12.503 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - [prepareWebApplicationContext,289] - Root WebApplicationContext: initialization completed in 946 ms
2021-12-14 20:09:12.553 [main] INFO c.c.t.f.TaskAuthFilter$$EnhancerBySpringCGLIB$$cc147867 - [init,41] - AuthF
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
分布式定时任务,封装了elastic-job-lite&elastic-job-lite-console,支持手动触发任.zip (119个子文件)
bootstrap.min.css 122KB
AdminLTE.min.css 84KB
_all-skins.min.css 41KB
font-awesome.min.css 28KB
bootstrap-theme.min.css 23KB
daterangepicker.css 8KB
bootstrap-table.min.css 6KB
index.css 1KB
fontawesome-webfont.eot 69KB
glyphicons-halflings-regular.eot 20KB
spring.factories 110B
.gitignore 2KB
build.gradle 6KB
add_job.html 20KB
job_config.html 19KB
index.html 15KB
job_status_history.html 6KB
job_event_trace_history.html 6KB
jobs_status_overview.html 3KB
job_status_detail.html 2KB
servers_status_overview.html 1KB
server_status_detail.html 1KB
help.html 870B
favicon.ico 8KB
JobEventRdbStorage.java 19KB
ScheduledTaskBeanProcessor.java 11KB
Job.java 11KB
ScheduledTaskBuilder.java 9KB
JobStatisticsServiceImpl.java 6KB
ScheduledTaskMonitor.java 6KB
JobOperateServiceImpl.java 5KB
ManualScheduledTaskListener.java 5KB
ScheduledTask.java 5KB
EventTraceHistoryController.java 5KB
JobSettingsServiceImpl.java 5KB
ServerOperationController.java 5KB
JobOperationController.java 3KB
TaskAuthFilter.java 3KB
ZookeeperConfig.java 3KB
ServerStatisticsServiceImpl.java 3KB
JobExecutionQueryInfo.java 2KB
ManuallyAddJobController.java 2KB
SpringUtil.java 2KB
ShardingInfo.java 2KB
ShardingStatisticsServiceImpl.java 2KB
TaskConstants.java 2KB
DistributedTaskExecutionListener.java 2KB
ZookeeperUtil.java 2KB
JobBriefInfo.java 2KB
ServerBriefInfo.java 2KB
LiteJobConfigController.java 2KB
JSONUtil.java 2KB
JSONResult.java 2KB
JobProperties.java 1KB
ScheduledTaskConfig.java 1KB
IJobAPIServiceImpl.java 1KB
JobEventRdbConfiguration.java 1KB
IJobOperateService.java 1KB
ShardingOperateServiceImpl.java 1KB
ShutDownApplicationEvent.java 1KB
JobEventRdbListener.java 1KB
SpringJobSchedulerFacade.java 1KB
TaskScheduler.java 967B
ScheduledTaskExecutionListener.java 937B
AuthProperties.java 907B
ApplicationErrorListener.java 864B
IJobStatisticsService.java 826B
StaticWebResourcePathConfig.java 634B
IJobSettingsService.java 572B
IServerStatisticsService.java 508B
ScheduledTaskAutoConfiguration.java 448B
IShardingOperateService.java 432B
HeartBeatController.java 398B
IShardingStatisticsService.java 396B
IJobAPIService.java 377B
bootstrapValidator.js 300KB
bootstrap-table.js 108KB
jquery.inputmask.js 88KB
jquery-2.1.4.min.js 82KB
daterangepicker.js 68KB
moment.min.js 46KB
bootstrap.min.js 36KB
jquery.inputmask.date.extensions.js 22KB
bootstrapValidator_zh_CN.js 12KB
jobs_status_overview.js 10KB
app.min.js 9KB
jquery.inputmask.regex.extensions.js 9KB
jquery.inputmask.numeric.extensions.js 9KB
server_status_detail.js 5KB
servers_status_overview.js 5KB
jquery.inputmask.extensions.js 5KB
jquery.i18n.properties-min.js 4KB
job_status_detail.js 3KB
common.js 3KB
jquery.inputmask.phone.extensions.js 2KB
dashboard.js 1KB
formatter.js 1KB
index.js 816B
job_event_trace_history.js 347B
job_status_history.js 310B
共 119 条
- 1
- 2
资源评论
苹果酱0567
- 粉丝: 2062
- 资源: 1102
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- weixin小程序项目电子竞技信息交流平台+ssm.zip
- 基于MPC的三相变流器设计及仿真,仿真平台基于MATLAB Simulink搭建 内含仿真文件,源代码,设计文档,仿真图 设计文档包括建模,各部分仿真模块设计,控制算法详解
- weixin小程序项目电子购物系统的设计与实现+ssm.zip
- weixin小程序项目电影院订票选座小程序+ssm.zip
- weixin小程序项目大学生闲置物品交易平台的分析与设计+ssm.zip
- weixin小程序项目大学生心理健康服务+ssm.zip
- weixin小程序项目电影院订票选座系统设计及实现+ssm.zip
- weixin小程序项目宠物小程序+ssm.zip
- weixin小程序项目传染病防控宣传系统的设计与实现+springboot.zip
- weixin小程序项目大学生就业平台微信小程序+ssm.zip
- weixin小程序项目畅阅读微信小程序+ssm.zip
- 依据双碳而产生的模型,低碳优化调度 以系统运行维护成本,购能等方向作为优化目标 通过模型计算使各部分能达到最优值 考虑设备有燃气轮机、余热锅炉、燃气锅炉、热泵、电制冷机、储电系统
- 00-【管理制度】07-企业师带徒培训管理制度.doc
- 01-【师带徒协议】03-师带徒协议书.doc
- 01-【师带徒协议】02-师带徒协议书.doc
- 01-【师带徒协议】04-导师辅导协议书(师带徒协议书).docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功