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 <nfilo...@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; + } } }