监听器配置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:elasticjob="http://shardingsphere.apache.org/schema/elasticjob"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://shardingsphere.apache.org/schema/elasticjob
  8. http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd
  9. ">
  10. <!--配置作业注册中心 -->
  11. <elasticjob:zookeeper id="regCenter" server-lists="yourhost:2181" namespace="my-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" />
  12. <!-- 配置作业 Bean -->
  13. <bean id="myJob" class="xxx.MyJob" />
  14. <elasticjob:job id="${myJob.id}" job-ref="myJob" registry-center-ref="regCenter" sharding-total-count="3" cron="0/1 * * * * ?" job-listener-types="simpleJobListener,distributeOnceJobListener">
  15. </elasticjob:job>
  16. </beans>

作业启动

将配置 Spring 命名空间的 xml 通过 Spring 启动,作业将自动加载。