|
| 1 | +package com.github.cadecode.uniboot.common.plugin.job.config; |
| 2 | + |
| 3 | +import com.github.cadecode.uniboot.common.plugin.job.config.XxlJobProperties.XxlJobAdminProperties; |
| 4 | +import com.github.cadecode.uniboot.common.plugin.job.config.XxlJobProperties.XxlJobExecutorProperties; |
| 5 | +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; |
| 6 | +import lombok.extern.slf4j.Slf4j; |
| 7 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 8 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 9 | +import org.springframework.context.annotation.Bean; |
| 10 | +import org.springframework.context.annotation.Configuration; |
| 11 | + |
| 12 | +/** |
| 13 | + * xxl-job 自动配置 |
| 14 | + * |
| 15 | + * @author Cade Li |
| 16 | + * @since 2023/11/10 |
| 17 | + */ |
| 18 | +@Slf4j |
| 19 | +@ConditionalOnProperty(name = "xxl.job.enabled", havingValue = "true") |
| 20 | +@EnableConfigurationProperties({XxlJobProperties.class, XxlJobAdminProperties.class, XxlJobExecutorProperties.class}) |
| 21 | +@Configuration |
| 22 | +public class XxlJobAutoConfig { |
| 23 | + |
| 24 | + @Bean |
| 25 | + public XxlJobSpringExecutor xxlJobExecutor(XxlJobProperties xxlJobProperties, |
| 26 | + XxlJobAdminProperties adminProperties, |
| 27 | + XxlJobExecutorProperties executorProperties) { |
| 28 | + log.info("xxl-job config init"); |
| 29 | + // init executor |
| 30 | + XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); |
| 31 | + xxlJobSpringExecutor.setAdminAddresses(adminProperties.getAddresses()); |
| 32 | + xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken()); |
| 33 | + xxlJobSpringExecutor.setAppname(executorProperties.getAppname()); |
| 34 | + xxlJobSpringExecutor.setAddress(executorProperties.getAddress()); |
| 35 | + xxlJobSpringExecutor.setIp(executorProperties.getIp()); |
| 36 | + xxlJobSpringExecutor.setPort(executorProperties.getPort()); |
| 37 | + xxlJobSpringExecutor.setLogPath(executorProperties.getLogpath()); |
| 38 | + xxlJobSpringExecutor.setLogRetentionDays(executorProperties.getLogRetentionDays()); |
| 39 | + return xxlJobSpringExecutor; |
| 40 | + } |
| 41 | +} |
0 commit comments