提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.quartz.config; |
H |
2 |
|
|
3 |
import com.xxl.job.core.executor.XxlJobExecutor; |
|
4 |
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; |
|
5 |
import lombok.extern.slf4j.Slf4j; |
|
6 |
import org.springframework.boot.autoconfigure.AutoConfiguration; |
|
7 |
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
|
8 |
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
|
9 |
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|
10 |
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
11 |
import org.springframework.context.annotation.Bean; |
|
12 |
import org.springframework.context.annotation.Configuration; |
|
13 |
import org.springframework.scheduling.annotation.EnableScheduling; |
|
14 |
|
|
15 |
/** |
|
16 |
* XXL-Job 自动配置类 |
|
17 |
* |
|
18 |
* @author iailab |
|
19 |
*/ |
|
20 |
@AutoConfiguration |
|
21 |
@ConditionalOnClass(XxlJobSpringExecutor.class) |
|
22 |
@ConditionalOnProperty(prefix = "xxl.job", name = "enabled", havingValue = "true", matchIfMissing = true) |
|
23 |
@EnableConfigurationProperties({XxlJobProperties.class}) |
|
24 |
@EnableScheduling // 开启 Spring 自带的定时任务 |
|
25 |
@Slf4j |
|
26 |
public class IailabXxlJobAutoConfiguration { |
|
27 |
|
|
28 |
@Bean |
|
29 |
@ConditionalOnMissingBean |
|
30 |
public XxlJobExecutor xxlJobExecutor(XxlJobProperties properties) { |
|
31 |
log.info("[xxlJobExecutor][初始化 XXL-Job 执行器的配置]"); |
|
32 |
XxlJobProperties.AdminProperties admin = properties.getAdmin(); |
|
33 |
XxlJobProperties.ExecutorProperties executor = properties.getExecutor(); |
|
34 |
|
|
35 |
// 初始化执行器 |
|
36 |
XxlJobExecutor xxlJobExecutor = new XxlJobSpringExecutor(); |
|
37 |
xxlJobExecutor.setIp(executor.getIp()); |
|
38 |
xxlJobExecutor.setPort(executor.getPort()); |
|
39 |
xxlJobExecutor.setAppname(executor.getAppName()); |
|
40 |
xxlJobExecutor.setLogPath(executor.getLogPath()); |
|
41 |
xxlJobExecutor.setLogRetentionDays(executor.getLogRetentionDays()); |
|
42 |
xxlJobExecutor.setAdminAddresses(admin.getAddresses()); |
|
43 |
xxlJobExecutor.setAccessToken(properties.getAccessToken()); |
|
44 |
return xxlJobExecutor; |
|
45 |
} |
|
46 |
|
|
47 |
} |