This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new f7b2ccc0e6b3 CAMEL-27634: camel-cron - spring refuses a seven-part 
schedule, cronService matches ids and fails on no match (#31016)
f7b2ccc0e6b3 is described below

commit f7b2ccc0e6b33892e6844c76845950c73718ead9
Author: allthingssecurity <[email protected]>
AuthorDate: Sat Nov 28 03:22:05 2026 +0530

    CAMEL-27634: camel-cron - spring refuses a seven-part schedule, cronService 
matches ids and fails on no match (#31016)
    
    1. CronComponent accepts a schedule of five to seven parts, but
       CamelSpringCronService passed a seven-part one (with a year) as it was,
       and Spring's CronExpression has exactly six fields, so the route failed
       to start with "Cron expression must consist of 6 fields". The spring
       cron service now refuses it when the endpoint is created, with a
       message that names the spring cron service, as it does for the
       five-part schedules it cannot convert. The schedule option and the doc
       page say that camel-spring does not support the year.
    
    2. When cronService was set and no bean had that name, CronHelper fell
       back to the cron service found on the classpath without a word, so a
       typo or a bean that was not bound selected another implementation. The
       component now fails to start with a message that names the value, and
       the id of the cron service found on the classpath, if any.
    
    3. cronService did not match the id of a CamelCronService: cronService=
       quartz worked only with a bean named quartz, and with camel-quartz and
       camel-spring both on the classpath the classpath order picked the
       implementation. When no bean has the name, CronHelper now loads the
       factory key cron/cron-service-<name>, which camel-quartz
       (cron-service-quartz) and camel-spring (cron-service-spring) now
       provide, and else accepts the cron service of the classpath whose
       getId() is the name. A bean with the name still wins.
    
    Regenerated cron.json (component and catalog copy), and the endpoint and
    component DSL. Upgrade guide entry for 4.24.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../org/apache/camel/catalog/components/cron.json  |  4 +-
 .../apache/camel/catalog/docs/cron-component.adoc  |  3 +-
 .../org/apache/camel/component/cron/cron.json      |  4 +-
 .../camel-cron/src/main/docs/cron-component.adoc   |  3 +-
 .../apache/camel/component/cron/CronComponent.java |  7 +-
 .../apache/camel/component/cron/CronHelper.java    | 35 ++++++++-
 .../component/cron/api/CamelCronConfiguration.java |  4 +-
 .../camel/component/cron/CronServiceByIdTest.java  | 88 ++++++++++++++++++++++
 .../component/cron/OtherCamelCronService.java      | 27 +++++++
 .../org/apache/camel/cron/cron-service-other       | 17 +++++
 .../org/apache/camel/cron/cron-service-quartz      | 17 +++++
 .../quartz/cron/QuartzCronServiceByIdTest.java     | 39 ++++++++++
 .../component/cron/CamelSpringCronService.java     |  5 ++
 .../org/apache/camel/cron/cron-service-spring      | 17 +++++
 .../component/cron/CamelSpringCronServiceTest.java | 75 ++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    | 11 +++
 .../component/dsl/CronComponentBuilderFactory.java | 10 ++-
 .../endpoint/dsl/CronEndpointBuilderFactory.java   |  5 +-
 18 files changed, 351 insertions(+), 20 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/cron.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/cron.json
index 60eb5931414a..6df7ad644b36 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/cron.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/cron.json
@@ -26,14 +26,14 @@
   "componentProperties": {
     "bridgeErrorHandler": { "index": 0, "kind": "property", "displayName": 
"Bridge Error Handler", "group": "consumer", "label": "consumer", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": false, "description": 
"Allows for bridging the consumer to the Camel routing Error Handler, which 
mean any exceptions (if possible) occurred while the Camel consumer is trying 
to pickup incoming messages, or the like [...]
     "autowiredEnabled": { "index": 1, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"Whether autowiring is enabled. This is used for automatic autowiring options 
(the option must be marked as autowired) by looking up in the registry to find 
if there is a single instance of matching t [...]
-    "cronService": { "index": 2, "kind": "property", "displayName": "Cron 
Service", "group": "advanced", "label": "advanced", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "description": "The name of the CamelCronService bean 
in the registry to use, when more than one is bound. If not set, the only 
CamelCronService in the registry is used. If the registry has none, the one 
that a module on the classpath prov [...]
+    "cronService": { "index": 2, "kind": "property", "displayName": "Cron 
Service", "group": "advanced", "label": "advanced", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "description": "The CamelCronService to use. When set, 
it is the name of a CamelCronService bean in the registry, or the id of a 
classpath cron service (quartz for camel-quartz, spring for camel-spring). The 
component fails to start when n [...]
   },
   "bodyTypes": {
     "consumerOut": { "carriers": [ "null" ], "description": "No body: the 
message only starts the route" }
   },
   "properties": {
     "name": { "index": 0, "kind": "path", "displayName": "Name", "group": 
"consumer", "label": "", "required": true, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.cron.api.CamelCronConfiguration", 
"configurationField": "configuration", "description": "The name of the trigger, 
which the cron implementation uses to identify its job. With camel-quartz it is 
the name of the Quartz  [...]
-    "schedule": { "index": 1, "kind": "parameter", "displayName": "Schedule", 
"group": "consumer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "configurationClass": 
"org.apache.camel.component.cron.api.CamelCronConfiguration", 
"configurationField": "configuration", "description": "The cron expression of 
when to trigger, with five to seven parts separated by spaces: seconds 
(optional), minutes,  [...]
+    "schedule": { "index": 1, "kind": "parameter", "displayName": "Schedule", 
"group": "consumer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "configurationClass": 
"org.apache.camel.component.cron.api.CamelCronConfiguration", 
"configurationField": "configuration", "description": "The cron expression of 
when to trigger, with five to seven parts separated by spaces: seconds 
(optional), minutes,  [...]
     "bridgeErrorHandler": { "index": 2, "kind": "parameter", "displayName": 
"Bridge Error Handler", "group": "consumer (advanced)", "label": 
"consumer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Allows for bridging the consumer to the 
Camel routing Error Handler, which mean any exceptions (if possible) occurred 
while the Camel consumer is trying to pickup incoming  [...]
     "exceptionHandler": { "index": 3, "kind": "parameter", "displayName": 
"Exception Handler", "group": "consumer (advanced)", "label": 
"consumer,advanced", "required": false, "type": "object", "javaType": 
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", 
"deprecated": false, "autowired": false, "secret": false, "description": "To 
let the consumer use a custom ExceptionHandler. Notice if the option 
bridgeErrorHandler is enabled then this option is not in use. By def [...]
     "exchangePattern": { "index": 4, "kind": "parameter", "displayName": 
"Exchange Pattern", "group": "consumer (advanced)", "label": 
"consumer,advanced", "required": false, "type": "enum", "javaType": 
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ], 
"deprecated": false, "autowired": false, "secret": false, "description": "Sets 
the exchange pattern when the consumer creates an exchange." }
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cron-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cron-component.adoc
index 9270c67f00ca..b2784b7ea201 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cron-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cron-component.adoc
@@ -113,7 +113,8 @@ Schedule expressions can be made of five to seven parts. 
When expressions are co
 A five-part expression can also use the Unix cron syntax, with `*` in both day 
fields (for example `*/5 * * * *`).
 The day of month and the day of week cannot both be given. With camel-quartz, 
give the day of week by name (such as
 `MON-FRI`): a number is used as in Quartz, where Sunday is 1 (0 in Unix), and 
needs `?` in the day of month. With
-camel-spring, the day of week cannot use `*/n`.
+camel-spring, the day of week cannot use `*/n`, and the year cannot be given: 
a seven-part expression fails the
+endpoint with camel-spring, and works with camel-quartz.
 
 Other valid examples of schedule expressions are:
 
diff --git 
a/components/camel-cron/src/generated/resources/META-INF/org/apache/camel/component/cron/cron.json
 
b/components/camel-cron/src/generated/resources/META-INF/org/apache/camel/component/cron/cron.json
index 60eb5931414a..6df7ad644b36 100644
--- 
a/components/camel-cron/src/generated/resources/META-INF/org/apache/camel/component/cron/cron.json
+++ 
b/components/camel-cron/src/generated/resources/META-INF/org/apache/camel/component/cron/cron.json
@@ -26,14 +26,14 @@
   "componentProperties": {
     "bridgeErrorHandler": { "index": 0, "kind": "property", "displayName": 
"Bridge Error Handler", "group": "consumer", "label": "consumer", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": false, "description": 
"Allows for bridging the consumer to the Camel routing Error Handler, which 
mean any exceptions (if possible) occurred while the Camel consumer is trying 
to pickup incoming messages, or the like [...]
     "autowiredEnabled": { "index": 1, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"Whether autowiring is enabled. This is used for automatic autowiring options 
(the option must be marked as autowired) by looking up in the registry to find 
if there is a single instance of matching t [...]
-    "cronService": { "index": 2, "kind": "property", "displayName": "Cron 
Service", "group": "advanced", "label": "advanced", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "description": "The name of the CamelCronService bean 
in the registry to use, when more than one is bound. If not set, the only 
CamelCronService in the registry is used. If the registry has none, the one 
that a module on the classpath prov [...]
+    "cronService": { "index": 2, "kind": "property", "displayName": "Cron 
Service", "group": "advanced", "label": "advanced", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "description": "The CamelCronService to use. When set, 
it is the name of a CamelCronService bean in the registry, or the id of a 
classpath cron service (quartz for camel-quartz, spring for camel-spring). The 
component fails to start when n [...]
   },
   "bodyTypes": {
     "consumerOut": { "carriers": [ "null" ], "description": "No body: the 
message only starts the route" }
   },
   "properties": {
     "name": { "index": 0, "kind": "path", "displayName": "Name", "group": 
"consumer", "label": "", "required": true, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.cron.api.CamelCronConfiguration", 
"configurationField": "configuration", "description": "The name of the trigger, 
which the cron implementation uses to identify its job. With camel-quartz it is 
the name of the Quartz  [...]
-    "schedule": { "index": 1, "kind": "parameter", "displayName": "Schedule", 
"group": "consumer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "configurationClass": 
"org.apache.camel.component.cron.api.CamelCronConfiguration", 
"configurationField": "configuration", "description": "The cron expression of 
when to trigger, with five to seven parts separated by spaces: seconds 
(optional), minutes,  [...]
+    "schedule": { "index": 1, "kind": "parameter", "displayName": "Schedule", 
"group": "consumer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "configurationClass": 
"org.apache.camel.component.cron.api.CamelCronConfiguration", 
"configurationField": "configuration", "description": "The cron expression of 
when to trigger, with five to seven parts separated by spaces: seconds 
(optional), minutes,  [...]
     "bridgeErrorHandler": { "index": 2, "kind": "parameter", "displayName": 
"Bridge Error Handler", "group": "consumer (advanced)", "label": 
"consumer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Allows for bridging the consumer to the 
Camel routing Error Handler, which mean any exceptions (if possible) occurred 
while the Camel consumer is trying to pickup incoming  [...]
     "exceptionHandler": { "index": 3, "kind": "parameter", "displayName": 
"Exception Handler", "group": "consumer (advanced)", "label": 
"consumer,advanced", "required": false, "type": "object", "javaType": 
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", 
"deprecated": false, "autowired": false, "secret": false, "description": "To 
let the consumer use a custom ExceptionHandler. Notice if the option 
bridgeErrorHandler is enabled then this option is not in use. By def [...]
     "exchangePattern": { "index": 4, "kind": "parameter", "displayName": 
"Exchange Pattern", "group": "consumer (advanced)", "label": 
"consumer,advanced", "required": false, "type": "enum", "javaType": 
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ], 
"deprecated": false, "autowired": false, "secret": false, "description": "Sets 
the exchange pattern when the consumer creates an exchange." }
diff --git a/components/camel-cron/src/main/docs/cron-component.adoc 
b/components/camel-cron/src/main/docs/cron-component.adoc
index 9270c67f00ca..b2784b7ea201 100644
--- a/components/camel-cron/src/main/docs/cron-component.adoc
+++ b/components/camel-cron/src/main/docs/cron-component.adoc
@@ -113,7 +113,8 @@ Schedule expressions can be made of five to seven parts. 
When expressions are co
 A five-part expression can also use the Unix cron syntax, with `*` in both day 
fields (for example `*/5 * * * *`).
 The day of month and the day of week cannot both be given. With camel-quartz, 
give the day of week by name (such as
 `MON-FRI`): a number is used as in Quartz, where Sunday is 1 (0 in Unix), and 
needs `?` in the day of month. With
-camel-spring, the day of week cannot use `*/n`.
+camel-spring, the day of week cannot use `*/n`, and the year cannot be given: 
a seven-part expression fails the
+endpoint with camel-spring, and works with camel-quartz.
 
 Other valid examples of schedule expressions are:
 
diff --git 
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronComponent.java
 
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronComponent.java
index 92d03ccbdd1a..ce53237c9938 100644
--- 
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronComponent.java
+++ 
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronComponent.java
@@ -35,9 +35,10 @@ import org.apache.camel.util.ObjectHelper;
 public class CronComponent extends DefaultComponent {
 
     @Metadata(label = "advanced",
-              description = "The name of the CamelCronService bean in the 
registry to use, when more than one is bound. If"
-                            + " not set, the only CamelCronService in the 
registry is used. If the registry has none, the one"
-                            + " that a module on the classpath provides is 
used, such as camel-quartz or camel-spring.")
+              description = "The CamelCronService to use. When set, it is the 
name of a CamelCronService bean in the"
+                            + " registry, or the id of a classpath cron 
service (quartz for camel-quartz, spring for"
+                            + " camel-spring). The component fails to start 
when neither matches. When not set, the only"
+                            + " CamelCronService in the registry is used, or 
else the one from a classpath module.")
     private String cronService;
 
     private CamelCronService service;
diff --git 
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronHelper.java
 
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronHelper.java
index fbcf39ca0db5..93780d34380f 100644
--- 
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronHelper.java
+++ 
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronHelper.java
@@ -30,7 +30,14 @@ public final class CronHelper {
     }
 
     /**
-     * Helper to lookup/create an instance of {@link CamelCronService}
+     * Helper to lookup/create an instance of {@link CamelCronService}.
+     * <p>
+     * Without a name, the only {@link CamelCronService} of the registry is 
used, or else the one that a module on the
+     * classpath provides. With a name, the bean of the registry with this 
name is used, or else the cron service of a
+     * module on the classpath whose id is the name, such as quartz or spring. 
A name that matches neither fails.
+     *
+     * @throws IllegalArgumentException if {@code name} is set but matches 
neither a registry bean nor a classpath cron
+     *                                  service id
      */
     public static CamelCronService resolveCamelCronService(CamelContext 
context, String name) {
         // Lookup the registry first
@@ -44,8 +51,30 @@ public final class CronHelper {
             return service;
         }
 
-        // Fallback to factory finder
-        return ResolverHelper.resolveBootstrapService(context, FACTORY_KEY, 
CamelCronService.class).orElse(null);
+        if (ObjectHelper.isEmpty(name)) {
+            // Fallback to factory finder
+            return ResolverHelper.resolveBootstrapService(context, 
FACTORY_KEY, CamelCronService.class).orElse(null);
+        }
+
+        // the cron service of a module on the classpath, by its id, such as 
cron/cron-service-quartz
+        service = ResolverHelper.resolveBootstrapService(context, FACTORY_KEY 
+ "-" + name, CamelCronService.class)
+                .orElse(null);
+        if (service != null) {
+            return service;
+        }
+        // a module that has no cron service file of its id: its cron service 
when the id matches
+        service = ResolverHelper.resolveBootstrapService(context, FACTORY_KEY, 
CamelCronService.class).orElse(null);
+        if (service != null && name.equals(service.getId())) {
+            return service;
+        }
+        throw new IllegalArgumentException(
+                "Cannot find the CamelCronService " + name + " of the 
cronService option: no CamelCronService bean has"
+                                           + " this name, and no module on the 
classpath provides a cron service with"
+                                           + " this id (such as quartz for 
camel-quartz, or spring for camel-spring)"
+                                           + (service != null
+                                                   ? "; the cron service on 
the classpath has the id "
+                                                     + service.getId()
+                                                   : ""));
     }
 
 }
diff --git 
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/api/CamelCronConfiguration.java
 
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/api/CamelCronConfiguration.java
index 1200786cf2b1..01361a8636c8 100644
--- 
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/api/CamelCronConfiguration.java
+++ 
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/api/CamelCronConfiguration.java
@@ -34,8 +34,8 @@ public class CamelCronConfiguration {
 
     @UriParam(description = "The cron expression of when to trigger, with five 
to seven parts separated by spaces: seconds"
                             + " (optional), minutes, hours, day of month, 
month, day of week, and year (optional). A"
-                            + " five-part expression has no seconds and 
follows the Unix cron syntax. A + in the value is"
-                            + " read as a space.")
+                            + " five-part expression has no seconds and 
follows the Unix cron syntax. camel-spring does not"
+                            + " support the year. A + in the value is read as 
a space.")
     @Metadata(required = true)
     private String schedule;
 
diff --git 
a/components/camel-cron/src/test/java/org/apache/camel/component/cron/CronServiceByIdTest.java
 
b/components/camel-cron/src/test/java/org/apache/camel/component/cron/CronServiceByIdTest.java
new file mode 100644
index 000000000000..e5645c02ebf9
--- /dev/null
+++ 
b/components/camel-cron/src/test/java/org/apache/camel/component/cron/CronServiceByIdTest.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cron;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The cronService option selects a bean by name, or else the cron service of 
the classpath by its id, and fails when
+ * neither matches.
+ */
+public class CronServiceByIdTest extends CamelTestSupport {
+
+    @Test
+    void cronServiceSelectsTheCronServiceFileOfItsId() throws Exception {
+        startWithCronService("other");
+
+        assertInstanceOf(OtherCamelCronService.class, 
cronComponent().getService());
+    }
+
+    @Test
+    void cronServiceMatchesTheIdOfTheCronServiceOfTheClasspath() throws 
Exception {
+        startWithCronService("dummy");
+
+        assertEquals("dummy", cronComponent().getService().getId());
+    }
+
+    @Test
+    void cronServiceThatMatchesNoBeanAndNoIdFails() {
+        Exception e = assertThrows(Exception.class, () -> 
startWithCronService("nosuch"));
+        Throwable cause = e;
+        while (cause.getCause() != null) {
+            cause = cause.getCause();
+        }
+        assertInstanceOf(IllegalArgumentException.class, cause);
+        assertTrue(cause.getMessage().contains("nosuch"), cause.getMessage());
+        assertTrue(cause.getMessage().contains("the cron service on the 
classpath has the id dummy"), cause.getMessage());
+    }
+
+    @Test
+    void beanWinsOverTheIdOfTheClasspath() throws Exception {
+        context.getRegistry().bind("other", new DummyCamelCronService("bean"));
+
+        startWithCronService("other");
+
+        assertEquals("bean", cronComponent().getService().getId());
+    }
+
+    private CronComponent cronComponent() {
+        return context.getComponent("cron", CronComponent.class);
+    }
+
+    private void startWithCronService(String cronService) throws Exception {
+        cronComponent().setCronService(cronService);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("cron:tab?schedule=0/1 * * * * ?").to("mock:result");
+            }
+        });
+        context.start();
+    }
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+}
diff --git 
a/components/camel-cron/src/test/java/org/apache/camel/component/cron/OtherCamelCronService.java
 
b/components/camel-cron/src/test/java/org/apache/camel/component/cron/OtherCamelCronService.java
new file mode 100644
index 000000000000..18706b47da49
--- /dev/null
+++ 
b/components/camel-cron/src/test/java/org/apache/camel/component/cron/OtherCamelCronService.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cron;
+
+/**
+ * A cron service of the tests with the id other, found by the 
cron/cron-service-other file of the test resources.
+ */
+public class OtherCamelCronService extends DummyCamelCronService {
+
+    public OtherCamelCronService() {
+        super("other");
+    }
+}
diff --git 
a/components/camel-cron/src/test/resources/META-INF/services/org/apache/camel/cron/cron-service-other
 
b/components/camel-cron/src/test/resources/META-INF/services/org/apache/camel/cron/cron-service-other
new file mode 100644
index 000000000000..39e56dfa68de
--- /dev/null
+++ 
b/components/camel-cron/src/test/resources/META-INF/services/org/apache/camel/cron/cron-service-other
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+class=org.apache.camel.component.cron.OtherCamelCronService
diff --git 
a/components/camel-quartz/src/main/resources/META-INF/services/org/apache/camel/cron/cron-service-quartz
 
b/components/camel-quartz/src/main/resources/META-INF/services/org/apache/camel/cron/cron-service-quartz
new file mode 100644
index 000000000000..3ab9652d6100
--- /dev/null
+++ 
b/components/camel-quartz/src/main/resources/META-INF/services/org/apache/camel/cron/cron-service-quartz
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+class=org.apache.camel.component.quartz.cron.CamelQuartzCronService
diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/cron/QuartzCronServiceByIdTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/cron/QuartzCronServiceByIdTest.java
new file mode 100644
index 000000000000..3670c769a919
--- /dev/null
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/cron/QuartzCronServiceByIdTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.quartz.cron;
+
+import org.apache.camel.component.cron.CronComponent;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
+/**
+ * cronService=quartz selects the cron service of camel-quartz by its id, 
without a bean of that name.
+ */
+public class QuartzCronServiceByIdTest extends CamelTestSupport {
+
+    @Test
+    public void cronServiceQuartzSelectsTheQuartzCronService() {
+        CronComponent cron = context.getComponent("cron", CronComponent.class);
+        cron.setCronService("quartz");
+
+        context.getEndpoint("cron:tab?schedule=0+0/2+*+*+*+?");
+
+        assertInstanceOf(CamelQuartzCronService.class, cron.getService());
+    }
+}
diff --git 
a/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/component/cron/CamelSpringCronService.java
 
b/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/component/cron/CamelSpringCronService.java
index 295e91fb3a47..958b96ff1a60 100644
--- 
a/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/component/cron/CamelSpringCronService.java
+++ 
b/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/component/cron/CamelSpringCronService.java
@@ -52,6 +52,11 @@ public class CamelSpringCronService implements 
CamelCronService, CamelContextAwa
             }
             // the seconds are optional in the cron component but mandatory in 
Spring
             schedule = "0 " + schedule;
+        } else if (parts.length == 7) {
+            // Spring cron expressions have exactly six fields: no year
+            throw new IllegalArgumentException(
+                    "The seven-part schedule " + schedule + " has a year, 
which the spring cron service does not support:"
+                                               + " use a schedule without the 
year, or camel-quartz");
         }
         options.put("scheduler.cron", schedule);
         cronEndpoint.configureProperties(options);
diff --git 
a/components/camel-spring-parent/camel-spring/src/main/resources/META-INF/services/org/apache/camel/cron/cron-service-spring
 
b/components/camel-spring-parent/camel-spring/src/main/resources/META-INF/services/org/apache/camel/cron/cron-service-spring
new file mode 100644
index 000000000000..5f64b35be460
--- /dev/null
+++ 
b/components/camel-spring-parent/camel-spring/src/main/resources/META-INF/services/org/apache/camel/cron/cron-service-spring
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+class=org.apache.camel.component.cron.CamelSpringCronService
diff --git 
a/components/camel-spring-parent/camel-spring/src/test/java/org/apache/camel/component/cron/CamelSpringCronServiceTest.java
 
b/components/camel-spring-parent/camel-spring/src/test/java/org/apache/camel/component/cron/CamelSpringCronServiceTest.java
new file mode 100644
index 000000000000..4beb25fde8be
--- /dev/null
+++ 
b/components/camel-spring-parent/camel-spring/src/test/java/org/apache/camel/component/cron/CamelSpringCronServiceTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cron;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The spring cron service refuses a schedule with a year, which a Spring cron 
expression cannot have, and is found by
+ * its id.
+ */
+public class CamelSpringCronServiceTest {
+
+    private CamelContext context;
+
+    @BeforeEach
+    void createContext() {
+        context = new DefaultCamelContext();
+        context.start();
+    }
+
+    @AfterEach
+    void stopContext() {
+        context.stop();
+    }
+
+    @Test
+    void sevenPartScheduleFailsTheEndpoint() {
+        Exception e = assertThrows(Exception.class, () -> 
context.getEndpoint("cron:tab?schedule=0+0/2+*+*+*+MON-FRI+2030"));
+        Throwable cause = e;
+        while (cause.getCause() != null) {
+            cause = cause.getCause();
+        }
+        assertInstanceOf(IllegalArgumentException.class, cause);
+        assertTrue(cause.getMessage().contains("spring cron service") && 
cause.getMessage().contains("year"),
+                cause.getMessage());
+    }
+
+    @Test
+    void sixPartScheduleCreatesTheEndpoint() {
+        CronEndpoint endpoint = 
context.getEndpoint("cron:tab?schedule=0+0/2+*+*+*+MON-FRI", 
CronEndpoint.class);
+
+        assertInstanceOf(SpringCronEndpoint.class, endpoint.getEndpoint());
+    }
+
+    @Test
+    void cronServiceSpringSelectsTheSpringCronService() {
+        context.getComponent("cron", 
CronComponent.class).setCronService("spring");
+
+        context.getEndpoint("cron:tab?schedule=0+0/2+*+*+*+MON-FRI", 
CronEndpoint.class);
+
+        assertInstanceOf(CamelSpringCronService.class, 
context.getComponent("cron", CronComponent.class).getService());
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 35a3840f3748..66a6c2da1269 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -294,6 +294,17 @@ messages, and grew with each one. An exception from a 
predicate of `onException`
 Split is no longer added to it either, and is logged instead. Use 
`throwException(MyException.class, "...")`, or
 `exceptionType` and `message`, to get a new exception for each message, with 
the previous exception as suppressed.
 
+=== camel-cron - cronService can be the id of a cron service, and fails when 
nothing matches
+
+The `cronService` option can now also be the id of the cron service of a 
module on the classpath: `quartz` for
+camel-quartz or `spring` for camel-spring. This selects that module when both 
are on the classpath. When no
+`CamelCronService` bean has the name of `cronService` and no module on the 
classpath provides a cron service with that
+id, the component now fails to start. Before, it used the cron service found 
on the classpath without a warning.
+
+With camel-spring, a seven-part schedule (with a year) now fails when the 
endpoint is created, with a message that
+names the spring cron service. Before, the endpoint was created and the route 
failed to start, as a Spring cron
+expression has no year.
+
 === camel-support - a scheduled poll consumer is DOWN after a 
VirtualMachineError until the route is restarted
 
 When a poll of a scheduled poll consumer (such as `file`, `ftp` or 
`scheduler`) fails with a `VirtualMachineError`
diff --git 
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/CronComponentBuilderFactory.java
 
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/CronComponentBuilderFactory.java
index 691f160709d0..e296c03bbab7 100644
--- 
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/CronComponentBuilderFactory.java
+++ 
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/CronComponentBuilderFactory.java
@@ -103,10 +103,12 @@ public interface CronComponentBuilderFactory {
         }
     
         /**
-         * The name of the CamelCronService bean in the registry to use, when
-         * more than one is bound. If not set, the only CamelCronService in the
-         * registry is used. If the registry has none, the one that a module on
-         * the classpath provides is used, such as camel-quartz or 
camel-spring.
+         * The CamelCronService to use. When set, it is the name of a
+         * CamelCronService bean in the registry, or the id of a classpath cron
+         * service (quartz for camel-quartz, spring for camel-spring). The
+         * component fails to start when neither matches. When not set, the 
only
+         * CamelCronService in the registry is used, or else the one from a
+         * classpath module.
          * 
          * The option is a: &lt;code&gt;java.lang.String&lt;/code&gt; type.
          * 
diff --git 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CronEndpointBuilderFactory.java
 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CronEndpointBuilderFactory.java
index 5fe1aa8c4b4f..eba7c99252c0 100644
--- 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CronEndpointBuilderFactory.java
+++ 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CronEndpointBuilderFactory.java
@@ -49,8 +49,9 @@ public interface CronEndpointBuilderFactory {
          * The cron expression of when to trigger, with five to seven parts
          * separated by spaces: seconds (optional), minutes, hours, day of
          * month, month, day of week, and year (optional). A five-part
-         * expression has no seconds and follows the Unix cron syntax. A + in
-         * the value is read as a space.
+         * expression has no seconds and follows the Unix cron syntax.
+         * camel-spring does not support the year. A + in the value is read as 
a
+         * space.
          * 
          * The option is a: <code>java.lang.String</code> type.
          * 

Reply via email to