懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 1 package cn.stylefeng.guns.timer.config;
2
3 import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6 import org.springframework.beans.factory.annotation.Value;
7 import org.springframework.context.annotation.Bean;
8 import org.springframework.context.annotation.Configuration;
9 import org.springframework.context.annotation.PropertySource;
10
11 /**
12  * xxl-job config
13  *
14  * @author xuxueli 2017-04-28
15  */
16 @Configuration
17 @PropertySource("classpath:/xxl-job.properties")
18 public class JobExecutorConfig {
19     private Logger logger = LoggerFactory.getLogger(JobExecutorConfig.class);
20
21     @Value("${xxl.job.admin.addresses}")
22     private String adminAddresses;
23
24     @Value("${xxl.job.executor.appname}")
25     private String appName;
26
27     @Value("${xxl.job.executor.ip}")
28     private String ip;
29
30     @Value("${xxl.job.executor.port}")
31     private int port;
32
33     @Value("${xxl.job.accessToken}")
34     private String accessToken;
35
36     @Value("${xxl.job.executor.logpath}")
37     private String logPath;
38
39     @Value("${xxl.job.executor.logretentiondays}")
40     private int logRetentionDays;
41
42
43     @Bean(initMethod = "start", destroyMethod = "destroy")
44     public XxlJobSpringExecutor xxlJobExecutor() {
45         logger.info(">>>>>>>>>>> xxl-job config init.");
46         XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
47         xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
48         xxlJobSpringExecutor.setAppName(appName);
49         xxlJobSpringExecutor.setIp(ip);
50         xxlJobSpringExecutor.setPort(port);
51         xxlJobSpringExecutor.setAccessToken(accessToken);
52         xxlJobSpringExecutor.setLogPath(logPath);
53         xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
54
55         return xxlJobSpringExecutor;
56     }
57
58     /**
59      * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
60      *
61      *      1、引入依赖:
62      *          <dependency>
63      *             <groupId>org.springframework.cloud</groupId>
64      *             <artifactId>spring-cloud-commons</artifactId>
65      *             <version>${version}</version>
66      *         </dependency>
67      *
68      *      2、配置文件,或者容器启动变量
69      *          spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
70      *
71      *      3、获取IP
72      *          String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
73      */
74
75
76 }