alibaba/spring-cloud-alibaba · error · IOException

cron and oneTime shouldn't set together

Error message

cron and oneTime shouldn't set together

What it means

Thrown by JobSyncService.createJob when a job declared under spring.cloud.scheduling.schedulerx.jobs sets BOTH 'cron' and 'oneTime'. SchedulerX2 models a job as either a recurring schedule (cron) or a single fire-at time (oneTime); specifying both is ambiguous and the create path rejects it with IOException before issuing the CreateJob POP request.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/service/JobSyncService.java:278

		if (SchedulerxConstants.JOB_MODEL_MAPREDUCE_ALIAS.equals(jobProperty.getJobModel())) {
			request.setExecuteMode(ExecuteMode.BATCH.getKey());
		}
		else {
			request.setExecuteMode(jobProperty.getJobModel());
		}
		if (StringUtils.isNotEmpty(jobProperty.getDescription())) {
			request.setDescription(jobProperty.getDescription());
		}

		if (StringUtils.isNotEmpty(jobProperty.getContent())) {
			request.setContent(jobProperty.getContent());
		}

		String cron = jobProperty.getCron();
		String oneTime = jobProperty.getOneTime();
		if (StringUtils.isNotEmpty(cron) && StringUtils.isNotEmpty(oneTime)) {
			throw new IOException("cron and oneTime shouldn't set together");
		}
		if (cron != null && !cron.isEmpty()) {
			CronExpression cronExpression = new CronExpression(cron);
			Date now = new Date();
			Date nextData = cronExpression.getTimeAfter(now);
			Date next2Data = nextData == null ? null : cronExpression.getTimeAfter(nextData);
			if (nextData != null && next2Data != null) {
				long interval = TimeUnit.MILLISECONDS.toSeconds((next2Data.getTime() - nextData.getTime()));
				if (interval < SchedulerxConstants.SECOND_DELAY_MAX_VALUE) {
					request.setTimeType(TimeType.SECOND_DELAY.getValue());
					request.setTimeExpression(String.valueOf(interval < SchedulerxConstants.SECOND_DELAY_MIN_VALUE ?
							SchedulerxConstants.SECOND_DELAY_MIN_VALUE : interval));
				}
				else {
					request.setTimeType(TimeType.CRON.getValue());
					request.setTimeExpression(cron);
				}
			}

View on GitHub (pinned to 115d590110)

Solutions

  1. In the offending spring.cloud.scheduling.schedulerx.jobs.<name> block, remove either the 'cron' key or the 'oneTime' key so only one schedule type is declared.
  2. If you need both a recurring and a one-off run, split them into two separate job entries under .jobs.
  3. Audit all job definitions for accidental double-scheduling.

Example fix

# before
spring:
  cloud:
    scheduling:
      schedulerx:
        jobs:
          my-job:
            className: com.example.MyJob
            cron: "0 0 9 * * ?"
            oneTime: "2025-01-01 00:00:00"

# after (recurring only)
spring:
  cloud:
    scheduling:
      schedulerx:
        jobs:
          my-job:
            className: com.example.MyJob
            cron: "0 0 9 * * ?"
Defensive patterns

Strategy: validation

Validate before calling

for (Map.Entry<String, JobProperty> e : properties.getJobs().entrySet()) {
    JobProperty j = e.getValue();
    if (StringUtils.isNotEmpty(j.getCron()) && StringUtils.isNotEmpty(j.getOneTime())) {
        throw new IllegalStateException(
            "job '" + e.getKey() + "' must set cron OR oneTime, not both");
    }
}

Prevention

When it happens

Trigger: For each entry in spring.cloud.scheduling.schedulerx.jobs, createJob reads jobProperty.getCron() and jobProperty.getOneTime(); if StringUtils.isNotEmpty(cron) && StringUtils.isNotEmpty(oneTime) at JobSyncService.java:277-278, it throws. Triggered during job sync for a job that has both keys populated.

Common situations: Copy-pasting a job definition and leaving a stale 'oneTime' next to a new 'cron'; misunderstanding that oneTime is a one-shot ISO timestamp and not a fallback; YAML alias/merge inadvertently pulling in both keys.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/cbe4b51ff4091691. Report an issue: GitHub.