|
83 | 83 | * "fixedRate", "fixedDelay", or "cron" expression provided via the annotation.
|
84 | 84 | *
|
85 | 85 | * <p>This post-processor is automatically registered by Spring's
|
86 |
| - * {@code <task:annotation-driven>} XML element, and also by the |
| 86 | + * {@code <task:annotation-driven>} XML element and also by the |
87 | 87 | * {@link EnableScheduling @EnableScheduling} annotation.
|
88 | 88 | *
|
89 | 89 | * <p>Autodetects any {@link SchedulingConfigurer} instances in the container,
|
@@ -395,8 +395,7 @@ protected void processScheduled(Scheduled scheduled, Method method, Object bean)
|
395 | 395 | try {
|
396 | 396 | Runnable runnable = createRunnable(bean, method);
|
397 | 397 | boolean processedSchedule = false;
|
398 |
| - String errorMessage = |
399 |
| - "Exactly one of the 'cron', 'fixedDelay(String)', or 'fixedRate(String)' attributes is required"; |
| 398 | + String errorMessage = "Exactly one of the 'cron', 'fixedDelay' or 'fixedRate' attributes is required"; |
400 | 399 |
|
401 | 400 | Set<ScheduledTask> tasks = new LinkedHashSet<>(4);
|
402 | 401 |
|
@@ -455,7 +454,6 @@ protected void processScheduled(Scheduled scheduled, Method method, Object bean)
|
455 | 454 | processedSchedule = true;
|
456 | 455 | tasks.add(this.registrar.scheduleFixedDelayTask(new FixedDelayTask(runnable, fixedDelay, initialDelay)));
|
457 | 456 | }
|
458 |
| - |
459 | 457 | String fixedDelayString = scheduled.fixedDelayString();
|
460 | 458 | if (StringUtils.hasText(fixedDelayString)) {
|
461 | 459 | if (this.embeddedValueResolver != null) {
|
@@ -532,7 +530,13 @@ protected Runnable createRunnable(Object target, Method method) {
|
532 | 530 | }
|
533 | 531 |
|
534 | 532 | private static Duration toDuration(long value, TimeUnit timeUnit) {
|
535 |
| - return Duration.of(value, timeUnit.toChronoUnit()); |
| 533 | + try { |
| 534 | + return Duration.of(value, timeUnit.toChronoUnit()); |
| 535 | + } |
| 536 | + catch (Exception ex) { |
| 537 | + throw new IllegalArgumentException( |
| 538 | + "Unsupported unit " + timeUnit + " for value \"" + value + "\": " + ex.getMessage()); |
| 539 | + } |
536 | 540 | }
|
537 | 541 |
|
538 | 542 | private static Duration toDuration(String value, TimeUnit timeUnit) {
|
|
0 commit comments