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

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


The following commit(s) were added to refs/heads/main by this push:
     new 2405e36d33 Avoid duplicate processing of BindToRegistry target types 
in RouteBuilder CDI beans
2405e36d33 is described below

commit 2405e36d33b0eb104f6019ae7dd51b40cb4bc496
Author: James Netherton <[email protected]>
AuthorDate: Wed Dec 10 13:17:27 2025 +0000

    Avoid duplicate processing of BindToRegistry target types in RouteBuilder 
CDI beans
    
    Fixes #8059
---
 .../core/deployment/CamelRegistryProcessor.java    |  7 ++--
 .../component/bean/bind/BindToRegistryConfig.java  | 26 +++++++++++++++
 .../bean/bind/BindToRegistryProcessor.java         | 38 ++++++++++++++++++++++
 .../component/bean/bind/BindToRegistryRoutes.java  | 14 ++++++++
 .../bean/src/main/resources/application.properties |  2 ++
 .../quarkus/component/bean/BindToRegistryTest.java |  8 +++++
 6 files changed, 90 insertions(+), 5 deletions(-)

diff --git 
a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRegistryProcessor.java
 
b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRegistryProcessor.java
index 7c640dda5e..9c1e9c9563 100644
--- 
a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRegistryProcessor.java
+++ 
b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRegistryProcessor.java
@@ -52,7 +52,6 @@ import org.jboss.jandex.AnnotationInstance;
 import org.jboss.jandex.AnnotationTarget;
 import org.jboss.jandex.AnnotationValue;
 import org.jboss.jandex.ClassInfo;
-import org.jboss.jandex.ClassInfo.NestingType;
 import org.jboss.jandex.DotName;
 import org.jboss.jandex.FieldInfo;
 import org.jboss.jandex.MethodInfo;
@@ -209,10 +208,8 @@ public class CamelRegistryProcessor {
                     .filter(BindToRegistryBeanInfo::isValid)
                     // Filter out @BindToRegistry usage on RouteBuilder impls 
as Camel can already handle this internally
                     .filter(bindToRegistryBeanInfo -> camelRoutes.stream()
-                            .noneMatch(routeBuilder -> 
!bindToRegistryBeanInfo.getDeclaringType().nestingType()
-                                    .equals(NestingType.TOP_LEVEL)
-                                    && routeBuilder.getDotName()
-                                            
.equals(bindToRegistryBeanInfo.getDeclaringType().enclosingClass())))
+                            .noneMatch(routeBuilder -> 
routeBuilder.getDotName()
+                                    
.equals(bindToRegistryBeanInfo.getDeclaringType().name())))
                     // Filter any existing named beans compared to the 
@BindToRegistry bean name
                     .filter(bindToRegistryBeanInfo -> containerBeans.getBeans()
                             .stream()
diff --git 
a/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryConfig.java
 
b/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryConfig.java
new file mode 100644
index 0000000000..e1ae73c6bb
--- /dev/null
+++ 
b/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryConfig.java
@@ -0,0 +1,26 @@
+/*
+ * 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.quarkus.component.bean.bind;
+
+import io.smallrye.config.ConfigMapping;
+import io.smallrye.config.WithDefault;
+
+@ConfigMapping(prefix = "bind.to.registry.test")
+public interface BindToRegistryConfig {
+    @WithDefault("This is the default message")
+    String message();
+}
diff --git 
a/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryProcessor.java
 
b/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryProcessor.java
new file mode 100644
index 0000000000..e6c8bfe64f
--- /dev/null
+++ 
b/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryProcessor.java
@@ -0,0 +1,38 @@
+/*
+ * 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.quarkus.component.bean.bind;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class BindToRegistryProcessor implements Processor {
+    static final AtomicInteger COUNTER = new AtomicInteger();
+
+    private final String message;
+
+    public BindToRegistryProcessor(String message) {
+        COUNTER.incrementAndGet();
+        this.message = message;
+    }
+
+    @Override
+    public void process(Exchange exchange) {
+        exchange.getMessage().setBody(message.formatted(COUNTER.get()));
+    }
+}
diff --git 
a/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryRoutes.java
 
b/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryRoutes.java
index 7971fd1ebf..7c0a256ace 100644
--- 
a/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryRoutes.java
+++ 
b/integration-test-groups/foundation/bean/src/main/java/org/apache/camel/quarkus/component/bean/bind/BindToRegistryRoutes.java
@@ -17,13 +17,19 @@
 package org.apache.camel.quarkus.component.bean.bind;
 
 import io.quarkus.runtime.annotations.RegisterForReflection;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
 import org.apache.camel.BindToRegistry;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 
+@ApplicationScoped
 public class BindToRegistryRoutes extends RouteBuilder {
+    @Inject
+    BindToRegistryConfig config;
+
     @Override
     public void configure() throws Exception {
         from("direct:invokeBindToRegistryBean")
@@ -39,6 +45,9 @@ public class BindToRegistryRoutes extends RouteBuilder {
                         
exchange.getMessage().setBody(bean.hello("BindToRegistrySimpleBean"));
                     }
                 });
+
+        from("direct:checkBeanInstantiationCount")
+                .process("bindToRegistryProcessor");
     }
 
     @RegisterForReflection(fields = false)
@@ -48,4 +57,9 @@ public class BindToRegistryRoutes extends RouteBuilder {
             return "Hello " + name;
         }
     }
+
+    @BindToRegistry
+    public BindToRegistryProcessor bindToRegistryProcessor() {
+        return new BindToRegistryProcessor(config.message());
+    }
 }
diff --git 
a/integration-test-groups/foundation/bean/src/main/resources/application.properties
 
b/integration-test-groups/foundation/bean/src/main/resources/application.properties
index 9a092334b3..a565b3d57a 100644
--- 
a/integration-test-groups/foundation/bean/src/main/resources/application.properties
+++ 
b/integration-test-groups/foundation/bean/src/main/resources/application.properties
@@ -22,6 +22,8 @@ my.injected.property.a = Test @PropertyInject
 my.injected.property.d = Test @PropertyInject Setter Method
 my.injected.property.e = Test @PropertyInject Method Argument
 
+bind.to.registry.test.message=BindToRegistryProcessor instantiation count: %d
+
 # DataSource Test
 quarkus.datasource.db-kind = h2
 
diff --git 
a/integration-test-groups/foundation/bean/src/test/java/org/apache/camel/quarkus/component/bean/BindToRegistryTest.java
 
b/integration-test-groups/foundation/bean/src/test/java/org/apache/camel/quarkus/component/bean/BindToRegistryTest.java
index 4411b60a82..af12ca7a76 100644
--- 
a/integration-test-groups/foundation/bean/src/test/java/org/apache/camel/quarkus/component/bean/BindToRegistryTest.java
+++ 
b/integration-test-groups/foundation/bean/src/test/java/org/apache/camel/quarkus/component/bean/BindToRegistryTest.java
@@ -52,4 +52,12 @@ class BindToRegistryTest {
                 .then()
                 .body(equalTo("Hello CDI Bean"));
     }
+
+    @Test
+    void bindToRegistryBeanInstantiationCount() {
+        RestAssured.given()
+                .get("/bean/route/checkBeanInstantiationCount")
+                .then()
+                .body(equalTo("BindToRegistryProcessor instantiation count: 
1"));
+    }
 }

Reply via email to