+++ title = “Spring Boot Starter” weight = 2 chapter = true +++

To use the Spring boot, user need to add the dependency of the elasticjob-lite-spring-boot-starter module in the pom.xml file.

<dependency>
    <groupId>org.apache.shardingsphere.elasticjob</groupId>
    <artifactId>elasticjob-lite-spring-boot-starter</artifactId>
    <version>${latest.release.version}</version>
</dependency>

Registry Center Configuration

Prefix: elasticjob.reg-center

Configuration:

Property nameRequired
server-listsYes
namespaceYes
base-sleep-time-millisecondsNo
max-sleep-time-millisecondsNo
max-retriesNo
session-timeout-millisecondsNo
connection-timeout-millisecondsNo
digestNo

Reference:

YAML

elasticjob:
  regCenter:
    serverLists: localhost:6181
    namespace: elasticjob-lite-springboot

Properties

elasticjob.reg-center.namespace=elasticjob-lite-springboot
elasticjob.reg-center.server-lists=localhost:6181

Job Configuration

Prefix: elasticjob.jobs

Configuration:

Property nameRequired
elasticJobClass / elasticJobTypeYes
cronNo
timeZoneNo
jobBootstrapBeanNameNo
sharding-total-countYes
sharding-item-parametersNo
job-parameterNo
monitor-executionNo
failoverNo
misfireNo
max-time-diff-secondsNo
reconcile-interval-minutesNo
job-sharding-strategy-typeNo
job-executor-service-handler-typeNo
job-error-handler-typeNo
job-listener-typesNo
descriptionNo
propsNo
disabledNo
overwriteNo

“elasticJobClass” and “elasticJobType” are mutually exclusive.

If cron was configured, the job will be created as a ScheduleJobBootstrap. The Starter will start scheduling when application is ready. Otherwise, the job will be created as a OneOffJobBootstrap with a name specified by “jobBootstrapBeanName”. It requires manual injection and execution.

Reference:

YAML

elasticjob:
  jobs:
    simpleJob:
      elasticJobClass: org.apache.shardingsphere.elasticjob.lite.example.job.SpringBootSimpleJob
      cron: 0/5 * * * * ?
      timeZone: GMT+08:00
      shardingTotalCount: 3
      shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou
    scriptJob:
      elasticJobType: SCRIPT
      cron: 0/10 * * * * ?
      shardingTotalCount: 3
      props:
        script.command.line: "echo SCRIPT Job: "
    manualScriptJob:
      elasticJobType: SCRIPT
      jobBootstrapBeanName: manualScriptJobBean
      shardingTotalCount: 9
      props:
        script.command.line: "echo Manual SCRIPT Job: "

Properties

elasticjob.jobs.simpleJob.elastic-job-class=org.apache.shardingsphere.elasticjob.lite.example.job.SpringBootSimpleJob
elasticjob.jobs.simpleJob.cron=0/5 * * * * ?
elasticjob.jobs.simpleJob.timeZone=GMT+08:00
elasticjob.jobs.simpleJob.sharding-total-count=3
elasticjob.jobs.simpleJob.sharding-item-parameters=0=Beijing,1=Shanghai,2=Guangzhou
elasticjob.jobs.scriptJob.elastic-job-type=SCRIPT
elasticjob.jobs.scriptJob.cron=0/5 * * * * ?
elasticjob.jobs.scriptJob.sharding-total-count=3
elasticjob.jobs.scriptJob.props.script.command.line=echo SCRIPT Job:
elasticjob.jobs.manualScriptJob.elastic-job-type=SCRIPT
elasticjob.jobs.manualScriptJob.job-bootstrap-bean-name=manualScriptJobBean
elasticjob.jobs.manualScriptJob.sharding-total-count=3
elasticjob.jobs.manualScriptJob.props.script.command.line=echo Manual SCRIPT Job:

Event Trace Configuration

Prefix: elasticjob.tracing

Property nameOptionsRequired
typeRDBNo

RDB is the only supported type at present. If Spring IoC container contained a bean of DataSource and RDB was set in configuration, an instance of TracingConfiguration will be created automatically.

Reference:

YAML

elasticjob:
  tracing:
    type: RDB

Properties

elasticjob.tracing.type=RDB

Dump Job Info Configuration

Prefix: elasticjob.dump

Property nameDefault valueRequired
enabledtrueNo
portYes

Designate a port as dump port in configurations. The Spring Boot Starter will enable dumping automatically. If the port for job dump was missing, dump won't be enabled.

Reference:

YAML

elasticjob:
  dump:
    port: 9888

Properties

elasticjob.dump.port=9888