You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2024/03/12 07:20:44 UTC

(camel) branch CAMEL-20551/fix-findSingleByType-4.4 created (now 84de0065d50)

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

nfilotto pushed a change to branch CAMEL-20551/fix-findSingleByType-4.4
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 84de0065d50 CAMEL-20551: camel-core - Avoid ignoring beans when using several repos (#13446)

This branch includes the following new commits:

     new 84de0065d50 CAMEL-20551: camel-core - Avoid ignoring beans when using several repos (#13446)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-20551: camel-core - Avoid ignoring beans when using several repos (#13446)

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-20551/fix-findSingleByType-4.4
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 84de0065d5020ea015ffa098cb50f24d60cabb9b
Author: Nicolas Filotto <es...@users.noreply.github.com>
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;
+                }
             }
         }