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

davsclaus pushed a commit to branch lazy
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 65f678f32e447f64f346a1d66a2dd6e5182e17c2
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Aug 29 09:45:04 2024 +0200

    CAMEL-21137: camel-core - Add lazy option to @BindToRegistry
---
 core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java    | 4 ++--
 .../impl/engine/DefaultDependencyInjectionAnnotationFactory.java     | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java 
b/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java
index 071311f64dd..7cf2bd2d43f 100644
--- a/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java
+++ b/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java
@@ -48,8 +48,8 @@ public @interface BindToRegistry {
     boolean beanPostProcess() default false;
 
     /**
-     * Whether to create the bean instance lazy (on-demand) instead of 
creating eager.
-     * Using lazy can be useful when you only need to create beans if they are 
explicit in-use.
+     * Whether to create the bean instance lazy (on-demand) instead of 
creating eager. Using lazy can be useful when you
+     * only need to create beans if they are explicit in-use.
      */
     boolean lazy() default false;
 }
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultDependencyInjectionAnnotationFactory.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultDependencyInjectionAnnotationFactory.java
index 4994eaafa53..1e1dcf70d11 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultDependencyInjectionAnnotationFactory.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultDependencyInjectionAnnotationFactory.java
@@ -48,6 +48,7 @@ public class DefaultDependencyInjectionAnnotationFactory
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public Runnable createBindToRegistryFactory(
             String id, Object bean, Class<?> beanType, String beanName, 
boolean beanPostProcess) {
         return () -> {
@@ -61,7 +62,9 @@ public class DefaultDependencyInjectionAnnotationFactory
                 }
             }
             CamelContextAware.trySetCamelContext(bean, camelContext);
-            if (bean instanceof Supplier<?> sup) {
+            if (bean instanceof Supplier) {
+                // must be Supplier<Object> to ensure correct binding
+                Supplier<Object> sup = (Supplier<Object>) bean;
                 camelContext.getRegistry().bind(id, beanType, sup);
             } else {
                 camelContext.getRegistry().bind(id, bean);

Reply via email to