XxlJobConfig.kt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.gxzc.zen.job.config
  2. import com.xxl.job.core.executor.XxlJobExecutor
  3. import org.mybatis.spring.annotation.MapperScan
  4. import org.slf4j.LoggerFactory
  5. import org.springframework.beans.factory.annotation.Value
  6. import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
  7. import org.springframework.context.annotation.Bean
  8. import org.springframework.context.annotation.Configuration
  9. /**
  10. *
  11. * @author NorthLan at 2018/2/8
  12. */
  13. @Configuration
  14. @ConditionalOnProperty(prefix = "xxl.job", name = ["enable"], havingValue = "true", matchIfMissing = true)
  15. @MapperScan(basePackages = ["com.gxzc.zen.job.jobhandler"])
  16. class XxlJobConfig {
  17. companion object {
  18. private val logger = LoggerFactory.getLogger(XxlJobConfig::class.java)
  19. }
  20. @Value("\${xxl.job.admin.address}")
  21. private val adminAddress: String? = null
  22. @Value("\${xxl.job.executor.appname}")
  23. private val appName: String? = null
  24. @Value("\${xxl.job.executor.ip}")
  25. private val ip: String? = null
  26. @Value("\${xxl.job.executor.port}")
  27. private val port: Int = 0
  28. @Value("\${xxl.job.accessToken}")
  29. private val accessToken: String? = null
  30. @Value("\${xxl.job.executor.logpath}")
  31. private val logPath: String? = null
  32. @Value("\${xxl.job.executor.logretentiondays}")
  33. private val logRetentionDays: Int = 0
  34. @Bean
  35. fun xxlJobExecutor(): XxlJobExecutor {
  36. logger.info(">>>>>>>>>>>> xxl-job executor config init...")
  37. return XxlJobExecutor().also {
  38. it.setAdminAddresses(adminAddress)
  39. it.setAppName(appName)
  40. it.setIp(ip)
  41. it.setPort(port)
  42. it.setAccessToken(accessToken)
  43. it.setLogPath(logPath)
  44. it.setLogRetentionDays(logRetentionDays)
  45. }
  46. }
  47. }