Bean的实现类
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/***/
@Slf4j
@Configuration
@EnableConfigurationProperties(XxlJobProps.class)
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class XxlJobConfig {private final XxlJobProps xxlJobProps;@Bean(initMethod = "start", destroyMethod = "destroy")public XxlJobSpringExecutor xxlJobExecutor() {log.info(">>>>>>>>>>> xxl-job config init.");XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();xxlJobSpringExecutor.setAdminAddresses(xxlJobProps.getAdmin().getAddress());xxlJobSpringExecutor.setLogPath(xxlJobProps.getLog().getConfig());xxlJobSpringExecutor.setAccessToken(xxlJobProps.getAccessToken());xxlJobSpringExecutor.setAppname(xxlJobProps.getExecutor().getAppName());xxlJobSpringExecutor.setIp(xxlJobProps.getExecutor().getIp());xxlJobSpringExecutor.setPort(xxlJobProps.getExecutor().getPort());xxlJobSpringExecutor.setLogPath(xxlJobProps.getExecutor().getLogPath());xxlJobSpringExecutor.setLogRetentionDays(xxlJobProps.getExecutor().getLogRetentionDays());return xxlJobSpringExecutor;}}
application-dev.yml文件参数
xxl:job:admin:address: http://你的xxl-job访问地址:端口/xxl-job-adminaccessToken: default_tokenexecutor:appName: falcon-taskslogPath: ./jobhandlerlogRetentionDays: 30port: 19999ip:log:config: classpath:logback-spring.xml
XxlJobProps:从yml文件中映射到实体类。方便被调用
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;/*** Description: xxl-job 配置**/
@Data
@ConfigurationProperties(prefix = "xxl.job")
public class XxlJobProps {/*** 调度中心配置*/private XxlJobAdminProps admin;/*** 日志配置*/private XxlJobLogProps log;/*** 执行器配置*/private XxlJobExecutorProps executor;/*** 与调度中心交互的accessToken*/private String accessToken;@Datapublic static class XxlJobAdminProps {/*** 调度中心地址*/private String address;}@Datapublic static class XxlJobLogProps {/*** 配置地址*/private String config;}@Datapublic static class XxlJobExecutorProps {/*** 执行器名称*/private String appName;/*** 执行器 IP*/private String ip;/*** 执行器端口*/private int port;/*** 执行器日志*/private String logPath;/*** 执行器日志保留天数,-1*/private int logRetentionDays;}}