feat: SpringBoot 整合 xxl-job
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
package com.youlai.system.framework.xxljob;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxl-job config
|
||||||
|
*
|
||||||
|
* @author xuxueli 2017-04-28
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnProperty(name = "xxl.job.enabled")// xxl.job.enabled = true 才会自动配置
|
||||||
|
@Slf4j
|
||||||
|
public class XxlJobConfig {
|
||||||
|
|
||||||
|
@Value("${xxl.job.admin.addresses}")
|
||||||
|
private String adminAddresses;
|
||||||
|
|
||||||
|
@Value("${xxl.job.accessToken}")
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.appname}")
|
||||||
|
private String appname;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.address}")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.ip}")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.port}")
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logpath}")
|
||||||
|
private String logPath;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logretentiondays}")
|
||||||
|
private int logRetentionDays;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||||
|
log.info(">>>>>>>>>>> xxl-job config init.");
|
||||||
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||||
|
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||||
|
xxlJobSpringExecutor.setAppname(appname);
|
||||||
|
xxlJobSpringExecutor.setAddress(address);
|
||||||
|
xxlJobSpringExecutor.setIp(ip);
|
||||||
|
xxlJobSpringExecutor.setPort(port);
|
||||||
|
xxlJobSpringExecutor.setAccessToken(accessToken);
|
||||||
|
xxlJobSpringExecutor.setLogPath(logPath);
|
||||||
|
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
|
||||||
|
|
||||||
|
return xxlJobSpringExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.youlai.system.framework.xxljob;
|
||||||
|
|
||||||
|
import com.xxl.job.core.context.XxlJobHelper;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class XxlJobSampleHandler {
|
||||||
|
@XxlJob("demoJobHandler")
|
||||||
|
public void demoJobHandler() throws Exception {
|
||||||
|
XxlJobHelper.log("XXL-JOB, Hello World.");
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
XxlJobHelper.log("beat at:" + i);
|
||||||
|
TimeUnit.SECONDS.sleep(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -78,7 +78,26 @@ springdoc:
|
|||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
# 验证码配置
|
# 验证码配置
|
||||||
easycaptcha:
|
easy-captcha:
|
||||||
enable: true
|
enable: true
|
||||||
|
# 验证码类型: arithmetic-算术
|
||||||
type: arithmetic
|
type: arithmetic
|
||||||
|
# 验证码有效时间(单位:秒)
|
||||||
ttl: 120
|
ttl: 120
|
||||||
|
|
||||||
|
# xxl-job 定时任务配置
|
||||||
|
xxl:
|
||||||
|
job:
|
||||||
|
# xxl-job 开关
|
||||||
|
enabled: false
|
||||||
|
admin:
|
||||||
|
# 多个地址使用,分割
|
||||||
|
addresses: http://127.0.0.1:8080/xxl-job-admin
|
||||||
|
accessToken: default_token
|
||||||
|
executor:
|
||||||
|
appname: xxl-job-executor-${spring.application.name}
|
||||||
|
address:
|
||||||
|
ip:
|
||||||
|
port: 9999
|
||||||
|
logpath: /data/applogs/xxl-job/jobhandler
|
||||||
|
logretentiondays: 30
|
||||||
|
|||||||
@@ -61,7 +61,26 @@ springdoc:
|
|||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
# 验证码配置
|
# 验证码配置
|
||||||
easycaptcha:
|
easy-captcha:
|
||||||
enable: true
|
enable: true
|
||||||
|
# 验证码类型: arithmetic-算术
|
||||||
type: arithmetic
|
type: arithmetic
|
||||||
|
# 验证码有效时间(单位:秒)
|
||||||
ttl: 120
|
ttl: 120
|
||||||
|
|
||||||
|
# xxl-job 定时任务配置
|
||||||
|
xxl:
|
||||||
|
job:
|
||||||
|
# xxl-job 开关
|
||||||
|
enabled: false
|
||||||
|
admin:
|
||||||
|
# 多个地址使用,分割
|
||||||
|
addresses: http://127.0.0.1:8080/xxl-job-admin
|
||||||
|
accessToken: default_token
|
||||||
|
executor:
|
||||||
|
appname: xxl-job-executor-${spring.application.name}
|
||||||
|
address:
|
||||||
|
ip:
|
||||||
|
port: 9999
|
||||||
|
logpath: /data/applogs/xxl-job/jobhandler
|
||||||
|
logretentiondays: 30
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
config.name: application-dev.properties
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
config:
|
|
||||||
name: application-dev.yml
|
|
||||||
|
|
||||||
server:
|
|
||||||
port: 8989
|
|
||||||
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
url: jdbc:mysql://www.youlai.tech:3306/youlai_boot?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
|
|
||||||
username: youlai
|
|
||||||
password: 123456
|
|
||||||
data:
|
|
||||||
redis:
|
|
||||||
database: 6
|
|
||||||
host: www.youlai.tech
|
|
||||||
port: 6379
|
|
||||||
password: 123456
|
|
||||||
timeout: 10s
|
|
||||||
lettuce:
|
|
||||||
pool:
|
|
||||||
min-idle: 0
|
|
||||||
max-idle: 8
|
|
||||||
max-active: 8
|
|
||||||
max-wait: -1ms
|
|
||||||
|
|
||||||
mybatis-plus:
|
|
||||||
global-config:
|
|
||||||
db-config:
|
|
||||||
# 主键ID类型
|
|
||||||
id-type: none
|
|
||||||
logic-delete-field: deleted
|
|
||||||
logic-delete-value: 1
|
|
||||||
logic-not-delete-value: 0
|
|
||||||
configuration:
|
|
||||||
# 驼峰下划线转换
|
|
||||||
map-underscore-to-camel-case: true
|
|
||||||
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
|
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|
||||||
|
|
||||||
# 认证配置
|
|
||||||
auth:
|
|
||||||
token:
|
|
||||||
secret_key: SecretKey012345678901234567890123456789012345678901234567890123456789
|
|
||||||
# token 有效期(单位:秒)
|
|
||||||
token_validity: 18000
|
|
||||||
|
|
||||||
# MinIO 分布式文件系统
|
|
||||||
minio:
|
|
||||||
endpoint: http://localhost:9000
|
|
||||||
access-key: minioadmin
|
|
||||||
secret-key: minioadmin
|
|
||||||
# 存储桶名称
|
|
||||||
bucket-name: default
|
|
||||||
# 自定义域名(非必须),Nginx配置反向代理转发文件路径
|
|
||||||
custom-domain:
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
config:
|
|
||||||
name: application-test.yml
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
config.name: application.properties
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
spring:
|
|
||||||
application:
|
|
||||||
name: youlai-boot
|
|
||||||
profiles:
|
|
||||||
active: dev
|
|
||||||
|
|
||||||
config:
|
|
||||||
name: application.yml
|
|
||||||
Reference in New Issue
Block a user