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

davsclaus pushed a commit to branch fix/CAMEL-24105
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 1cd6fff58ef7c982a209d875bade37537259fd18
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jul 16 10:14:47 2026 +0200

    CAMEL-24105: camel-bean - Do not register annotation-driven EIP processors 
as CamelContext services
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../apache/camel/component/bean/MethodInfo.java    | 18 ------
 .../bean/BeanAnnotationServiceLeakTest.java        | 64 ++++++++++++++++++++++
 2 files changed, 64 insertions(+), 18 deletions(-)

diff --git 
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
 
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
index ba17b054f4da..cdf4bad5055c 100644
--- 
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
+++ 
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
@@ -139,12 +139,6 @@ public class MethodInfo {
         if (routingSlipAnnotation != null) {
             routingSlip = 
PluginHelper.getAnnotationBasedProcessorFactory(camelContext)
                     .createRoutingSlip(camelContext, routingSlipAnnotation);
-            // add created routingSlip as a service so we have its lifecycle 
managed
-            try {
-                camelContext.addService(routingSlip);
-            } catch (Exception e) {
-                throw RuntimeCamelException.wrapRuntimeCamelException(e);
-            }
         }
 
         DynamicRouter dynamicRouterAnnotation
@@ -152,12 +146,6 @@ public class MethodInfo {
         if (dynamicRouterAnnotation != null) {
             dynamicRouter = 
PluginHelper.getAnnotationBasedProcessorFactory(camelContext)
                     .createDynamicRouter(camelContext, 
dynamicRouterAnnotation);
-            // add created dynamicRouter as a service so we have its lifecycle 
managed
-            try {
-                camelContext.addService(dynamicRouter);
-            } catch (Exception e) {
-                throw RuntimeCamelException.wrapRuntimeCamelException(e);
-            }
         }
 
         RecipientList recipientListAnnotation
@@ -165,12 +153,6 @@ public class MethodInfo {
         if (recipientListAnnotation != null) {
             recipientList = 
PluginHelper.getAnnotationBasedProcessorFactory(camelContext)
                     .createRecipientList(camelContext, 
recipientListAnnotation);
-            // add created recipientList as a service so we have its lifecycle 
managed
-            try {
-                camelContext.addService(recipientList);
-            } catch (Exception e) {
-                throw RuntimeCamelException.wrapRuntimeCamelException(e);
-            }
         }
     }
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanAnnotationServiceLeakTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanAnnotationServiceLeakTest.java
new file mode 100644
index 000000000000..b02a430aaffc
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanAnnotationServiceLeakTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.bean;
+
+import java.util.Set;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.RoutingSlip;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Test that @RoutingSlip/@RecipientList/@DynamicRouter annotation processors 
are not registered as CamelContext
+ * services, which would cause a service leak when BeanInfo cache entries are 
evicted and re-created.
+ */
+public class BeanAnnotationServiceLeakTest extends ContextTestSupport {
+
+    @Test
+    public void testRoutingSlipAnnotationDoesNotLeakServices() throws 
Exception {
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello");
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello");
+
+        template.sendBody("direct:start", "Hello");
+
+        assertMockEndpointsSatisfied();
+
+        Set<org.apache.camel.processor.RoutingSlip> services
+                = 
context.hasServices(org.apache.camel.processor.RoutingSlip.class);
+        assertTrue(services.isEmpty(),
+                "RoutingSlip processor should not be registered as a 
CamelContext service, but found: " + services.size());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start").bean(new MyRoutingSlipBean());
+            }
+        };
+    }
+
+    public static class MyRoutingSlipBean {
+        @RoutingSlip
+        public String[] route(String body) {
+            return new String[] { "mock:foo", "mock:result" };
+        }
+    }
+}

Reply via email to