feat:定时任务开发
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.xiang.app;
|
||||
|
||||
import com.xiang.xmc.service.quartz.annotation.EnableXxzJob;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -15,6 +17,11 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
"com.xiang.xservice.logger",
|
||||
"com.xiang.app.common.config",
|
||||
})
|
||||
@MapperScan(basePackages = {
|
||||
"com.xiang.xmc.service.quartz",
|
||||
"com.xiang.app.modules.*.mapper"
|
||||
})
|
||||
@EnableXxzJob(basePackages = {"com.xiang.app.modules.*.schedule"})
|
||||
public class Application {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.xiang.app;
|
||||
|
||||
import com.xiang.xmc.service.quartz.domain.JobDefinition;
|
||||
import com.xiang.xmc.service.quartz.holder.JobDefinitionHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-31 14:19
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class JobScannerRun implements ApplicationRunner {
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
List<JobDefinition> jobDefinitions = JobDefinitionHolder.getAll();
|
||||
if (CollectionUtils.isEmpty(jobDefinitions)) {
|
||||
log.info("job 注册为空");
|
||||
}
|
||||
jobDefinitions.forEach(item -> {
|
||||
log.info("已注册job:" + item.getName());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,12 @@ spring:
|
||||
password: cornucopia@123
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
sshConnect: false
|
||||
xxz-job:
|
||||
url: jdbc:mysql://120.27.153.87:3306/xservice_quartz?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||
username: quartz
|
||||
password: quartz@123
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
sshConnect: false
|
||||
redis:
|
||||
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
||||
port: 6379
|
||||
@@ -29,6 +35,8 @@ spring:
|
||||
max-idle: 8
|
||||
min-idle: 0
|
||||
max-wait: 1000
|
||||
xxz-job:
|
||||
appName: xservice-cornucopia
|
||||
|
||||
dingtalk:
|
||||
robot:
|
||||
|
||||
Reference in New Issue
Block a user