您的位置:首页 > 新闻 > 会展 > xxl-job代码托管小片段

xxl-job代码托管小片段

2025/1/1 20:10:34 来源:https://blog.csdn.net/qq_34730277/article/details/139985068  浏览:    关键词:xxl-job代码托管小片段

 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;}}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com