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/11 18:58:08 UTC

(camel) branch CAMEL-20551/fix-findSingleByType created (now cd5826d8df4)

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

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


      at cd5826d8df4 CAMEL-20551: camel-core - Avoid ignoring beans when using several repos

This branch includes the following new commits:

     new cd5826d8df4 CAMEL-20551: camel-core - Avoid ignoring beans when using several repos

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

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
in repository https://gitbox.apache.org/repos/asf/camel.git

commit cd5826d8df4ea58f09f8df34c9817a61b0414954
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Mon Mar 11 19:57:42 2024 +0100

    CAMEL-20551: camel-core - Avoid ignoring beans when using several repos
---
 .../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;
+                }
             }
         }