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

nfilotto 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 2ebb4ee0cac CAMEL-20551: camel-core - Avoid ignoring beans when using 
several repos (#13446)
2ebb4ee0cac is described below

commit 2ebb4ee0cac78ec1a7c38dc2a3192a9eac284138
Author: Nicolas Filotto <[email protected]>
AuthorDate: Tue Mar 12 08:09:11 2024 +0100

    CAMEL-20551: camel-core - Avoid ignoring beans when using several repos 
(#13446)
    
    ## Motivation
    
    In case we have several bean repositories defined in the default registry 
and a bean is defined in one of the first bean repositories, the method 
findSingleByType won't return any result while we expect to retrieve a bean.
    
    ## Modifications:
    
    * Avoid ignoring the result of `findSingleByType` on the first bean 
repositories
---
 .../java/org/apache/camel/support/DefaultRegistryTest.java  | 13 +++++++++++++
 .../main/java/org/apache/camel/support/DefaultRegistry.java |  3 +++
 2 files changed, 16 insertions(+)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/support/DefaultRegistryTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/support/DefaultRegistryTest.java
index dec8b923e7c..3e1b1ac798e 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/support/DefaultRegistryTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/support/DefaultRegistryTest.java
@@ -276,6 +276,19 @@ public class DefaultRegistryTest {
         assertSame(context, lookup.getCamelContext());
     }
 
+    @Test
+    public void testFindSingleByTypeWithMultipleRepositories() {
+        SimpleRegistry sr = new SimpleRegistry();
+        Animal myAnimal = new Animal();
+        sr.bind("myAnimal", myAnimal);
+        registry.addBeanRepository(sr);
+
+        // Retrieve from the first bean repository
+        assertNotNull(registry.findSingleByType(Animal.class));
+        // Retrieve from the second bean repository
+        assertNotNull(registry.findSingleByType(Company.class));
+    }
+
     private static class MyBean implements CamelContextAware {
 
         private CamelContext camelContext;
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultRegistry.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultRegistry.java
index 76a9aa869f0..0c1971c9b19 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultRegistry.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultRegistry.java
@@ -365,6 +365,9 @@ public class DefaultRegistry extends ServiceSupport 
implements Registry, LocalBe
         if (found == null && repositories != null) {
             for (BeanRepository r : repositories) {
                 found = r.findSingleByType(type);
+                if (found != null) {
+                    break;
+                }
             }
         }
 

Reply via email to