To use the Spring namespace, user need to add the dependency of the elasticjob-spring module in the pom.xml file.
<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elasticjob-spring-namespace</artifactId>
<version>${latest.release.version}</version>
</dependency>
Spring namespace: http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd
The namespace module is compiled against Spring Framework 5.3, and it is tested with Spring Framework 6.2 and 7.0, the Spring Framework versions of Spring Boot 3.5 and 4.0. Spring Framework 6 and 7 require JDK 17 or above.
<elasticjob:zookeeper />
Configuration:
| Name | Required |
|---|---|
| id | Yes |
| server-lists | Yes |
| namespace | Yes |
| base-sleep-time-milliseconds | No |
| max-sleep-time-milliseconds | No |
| max-retries | No |
| session-timeout-milliseconds | No |
| connection-timeout-milliseconds | No |
| digest | No |
| ensemble-tracker | No |
<elasticjob:etcd />, <elasticjob:nacos /> and <elasticjob:memory /> are also supported.
Their attributes and examples are documented in the registry center section.
<elasticjob:job />
Configuration:
| Name | Required |
|---|---|
| id | Yes |
| class | No |
| job-ref | No |
| registry-center-ref | Yes |
| tracing-ref | No |
| cron | Yes |
| timeZone | No |
| sharding-total-count | Yes |
| sharding-item-parameters | No |
| job-parameter | No |
| monitor-execution | No |
| failover | No |
| misfire | No |
| max-time-diff-seconds | No |
| reconcile-interval-minutes | No |
| job-sharding-strategy-type | No |
| job-executor-service-handler-type | No |
| job-error-handler-type | No |
| job-listener-types | No |
| description | No |
| props | No |
| disabled | No |
| overwrite | No |
| label | No |
| static-sharding | No |
| max-wait-millis | No |
<elasticjob:job-scanner />
After declaring job configuration with @ElasticJobConfiguration, use the job scanner to register
schedule or one-off jobs by base package automatically.
A non-empty cron creates a ScheduleJobBootstrap which is scheduled automatically;
an empty cron creates a OneOffJobBootstrap which must be triggered manually.
Configuration:
| Name | Required | Description |
|---|---|---|
| id | Yes | Identify of the scanner in the Spring container |
| base-package | Yes | Base package to scan, single or comma-separated |
Reference:
<elasticjob:job-scanner id="jobScanner" base-package="org.example.job" />
<elasticjob:rdb-tracing />
Configuration:
| Name | Data Type | Required | Default Value | Description |
|---|---|---|---|---|
| id | String | Yes | The bean’s identify of the event tracing | |
| data-source-ref | DataSource | No | The bean’s name of the event tracing DataSource |
<elasticjob:snapshot />
Configuration:
| Name | Data Type | Required | Default Value | Description |
|---|---|---|---|---|
| id | String | Yes | The identify of the monitoring service in the Spring container | |
| registry-center-ref | String | Yes | Registry center bean’s reference, need to the statement of the reg:zookeeper |
|
| dump-port | String | Yes | Job dump port usage: echo “dump@jobName” | nc 127.0.0.1 9888 |