This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.10.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push:
new 489863558bc CAMEL-22056: camel-jbang - Annotation based dependency
injection with lazy-bean should should be registered as supplier based
489863558bc is described below
commit 489863558bc4ac2f5eea1c9cd5efb87abf89a69f
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon May 12 10:11:14 2025 +0200
CAMEL-22056: camel-jbang - Annotation based dependency injection with
lazy-bean should should be registered as supplier based
---
.../injection/AnnotationDependencyInjection.java | 27 +++++++++++++++++-----
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/injection/AnnotationDependencyInjection.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/injection/AnnotationDependencyInjection.java
index 07000bfa8aa..d5dc531a2de 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/injection/AnnotationDependencyInjection.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/injection/AnnotationDependencyInjection.java
@@ -48,6 +48,7 @@ import org.apache.camel.spi.TypeConverterRegistry;
import org.apache.camel.support.PluginHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ReflectionHelper;
+import org.apache.camel.util.StringHelper;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -212,7 +213,12 @@ public final class AnnotationDependencyInjection {
} else if (service != null &&
ObjectHelper.isNotEmpty(service.value())) {
name = service.value();
}
- bindBean(camelContext, name, instance, true);
+ if (name == null || name.isBlank()) {
+ name = clazz.getSimpleName();
+ // lower case first if using class name
+ name = StringHelper.decapitalize(name);
+ }
+ bindBean(camelContext, name, instance, instance.getClass(),
true);
}
}
}
@@ -270,7 +276,7 @@ public final class AnnotationDependencyInjection {
if (bi.name().length > 0) {
name = bi.name()[0];
}
- bindBean(context, name, instance, false);
+ bindBean(context, name, instance, method.getReturnType(),
false);
}
}
}
@@ -292,7 +298,12 @@ public final class AnnotationDependencyInjection {
if (named != null) {
name = named.value();
}
- bindBean(camelContext, name, instance, true);
+ if (name == null || name.isBlank()) {
+ name = clazz.getSimpleName();
+ // lower case first if using class name
+ name = StringHelper.decapitalize(name);
+ }
+ bindBean(camelContext, name, instance, instance.getClass(),
true);
}
}
}
@@ -348,13 +359,13 @@ public final class AnnotationDependencyInjection {
if (bi != null && !bi.value().isBlank()) {
name = bi.value();
}
- bindBean(context, name, instance, false);
+ bindBean(context, name, instance, method.getReturnType(),
false);
}
}
}
}
- private static void bindBean(CamelContext context, String name, Object
instance, boolean postProcess) {
+ private static void bindBean(CamelContext context, String name, Object
instance, Class<?> type, boolean postProcess) {
// to support hot reloading of beans then we need to enable unbind
mode in bean post processor
Registry registry = context.getRegistry();
CamelBeanPostProcessor bpp =
PluginHelper.getBeanPostProcessor(context);
@@ -362,7 +373,11 @@ public final class AnnotationDependencyInjection {
try {
// re-bind the bean to the registry
registry.unbind(name);
- registry.bind(name, instance);
+ if (instance instanceof Supplier sup) {
+ registry.bind(name, type, (Supplier<Object>) sup);
+ } else {
+ registry.bind(name, type, instance);
+ }
if (postProcess) {
bpp.postProcessBeforeInitialization(instance, name);
bpp.postProcessAfterInitialization(instance, name);