XxlJobConfig.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.gyee.generation.config;
  2. import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import org.springframework.context.EnvironmentAware;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.Configuration;
  8. import org.springframework.context.annotation.PropertySource;
  9. import org.springframework.core.env.Environment;
  10. /**
  11. * xxl-job config
  12. *
  13. * @author xuxueli 2017-04-28
  14. */
  15. @Configuration
  16. //@PropertySource("classpath:xxl-job-executor.properties")
  17. //@PropertySource("classpath:xxl-job-executor2.properties")
  18. @PropertySource("classpath:xxl-job-executor3.properties")
  19. //@PropertySource("classpath:xxl-job-executor4.properties")
  20. //@PropertySource("classpath:xxl-job-executorWPLY.properties")
  21. //@PropertySource("classpath:xxl-job-executorRG.properties")
  22. //@PropertySource("classpath:xxl-job-executorJN.properties")
  23. public class XxlJobConfig implements EnvironmentAware {
  24. private Environment env;
  25. @Override
  26. public void setEnvironment(Environment environment) {
  27. this.env=environment;
  28. }
  29. private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
  30. @Bean
  31. public XxlJobSpringExecutor xxlJobExecutor() {
  32. logger.info(">>>>>>>>>>> xxl-job config init.");
  33. XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
  34. xxlJobSpringExecutor.setAdminAddresses(env.getProperty("xxl.job.admin.addresses"));
  35. xxlJobSpringExecutor.setAppname(env.getProperty("xxl.job.executor.appname"));
  36. xxlJobSpringExecutor.setAddress(env.getProperty("xxl.job.executor.address"));
  37. xxlJobSpringExecutor.setIp(env.getProperty("xxl.job.executor.ip"));
  38. xxlJobSpringExecutor.setPort(Integer.parseInt(env.getProperty("xxl.job.executor.port")));
  39. xxlJobSpringExecutor.setAccessToken(env.getProperty("xxl.job.accessToken"));
  40. xxlJobSpringExecutor.setLogPath(env.getProperty("xxl.job.executor.logpath"));
  41. xxlJobSpringExecutor.setLogRetentionDays(Integer.parseInt(env.getProperty("xxl.job.executor.logretentiondays")));
  42. return xxlJobSpringExecutor;
  43. }
  44. /**
  45. * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
  46. *
  47. * 1、引入依赖:
  48. * <dependency>
  49. * <groupId>org.springframework.cloud</groupId>
  50. * <artifactId>spring-cloud-commons</artifactId>
  51. * <version>${version}</version>
  52. * </dependency>
  53. *
  54. * 2、配置文件,或者容器启动变量
  55. * spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
  56. *
  57. * 3、获取IP
  58. * String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
  59. */
  60. }