You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/07/04 08:45:21 UTC
[camel] 02/02: CAMEL-16776: Autowiring components should be done
last in the lifecycles as the customizer should run before to configure the
component options, so you can turn this on|off via configuration.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.11.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 19559d1156a09eb3824ef71f7993056a2bd2b3cf
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Jul 4 10:43:27 2021 +0200
CAMEL-16776: Autowiring components should be done last in the lifecycles as the customizer should run before to configure the component options, so you can turn this on|off via configuration.
---
.../java/org/apache/camel/impl/engine/AbstractCamelContext.java | 7 ++++---
.../camel/impl/engine/DefaultAutowiredLifecycleStrategy.java | 9 ++++++++-
.../org/apache/camel/main/MainAutowiredLifecycleStrategy.java | 9 ++++++++-
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index cee6d68..dbc792c 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -369,12 +369,12 @@ public abstract class AbstractCamelContext extends BaseService
// add a default LifecycleStrategy that discover strategies on the registry and invoke them
this.lifecycleStrategies.add(new OnCamelContextLifecycleStrategy());
- // add a default autowired strategy
- this.lifecycleStrategies.add(new DefaultAutowiredLifecycleStrategy(this));
-
// add a default LifecycleStrategy to customize services using customizers from registry
this.lifecycleStrategies.add(new CustomizersLifecycleStrategy(this));
+ // add a default autowired strategy
+ this.lifecycleStrategies.add(new DefaultAutowiredLifecycleStrategy(this));
+
// add the default bootstrap closer
this.bootstraps.add(new DefaultServiceBootstrapCloseable(this));
@@ -2669,6 +2669,7 @@ public abstract class AbstractCamelContext extends BaseService
forceLazyInitialization();
addService(getManagementStrategy(), false);
+ lifecycleStrategies.sort(OrderedComparator.get());
ServiceHelper.initService(lifecycleStrategies);
for (LifecycleStrategy strategy : lifecycleStrategies) {
try {
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultAutowiredLifecycleStrategy.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultAutowiredLifecycleStrategy.java
index 4261554..70301b4 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultAutowiredLifecycleStrategy.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultAutowiredLifecycleStrategy.java
@@ -21,6 +21,7 @@ import java.util.Set;
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.Ordered;
import org.apache.camel.spi.AutowiredLifecycleStrategy;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.spi.Language;
@@ -30,7 +31,7 @@ import org.apache.camel.support.LifecycleStrategySupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-class DefaultAutowiredLifecycleStrategy extends LifecycleStrategySupport implements AutowiredLifecycleStrategy {
+class DefaultAutowiredLifecycleStrategy extends LifecycleStrategySupport implements AutowiredLifecycleStrategy, Ordered {
private static final Logger LOG = LoggerFactory.getLogger(DefaultAutowiredLifecycleStrategy.class);
@@ -41,6 +42,12 @@ class DefaultAutowiredLifecycleStrategy extends LifecycleStrategySupport impleme
}
@Override
+ public int getOrder() {
+ // we should be last
+ return Ordered.LOWEST;
+ }
+
+ @Override
public void onComponentAdd(String name, Component component) {
autowireComponent(name, component);
}
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/main/MainAutowiredLifecycleStrategy.java b/core/camel-base-engine/src/main/java/org/apache/camel/main/MainAutowiredLifecycleStrategy.java
index c72bacc..a3b022e 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/main/MainAutowiredLifecycleStrategy.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/main/MainAutowiredLifecycleStrategy.java
@@ -23,6 +23,7 @@ import java.util.Set;
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.Ordered;
import org.apache.camel.VetoCamelContextStartException;
import org.apache.camel.spi.AutowiredLifecycleStrategy;
import org.apache.camel.spi.DataFormat;
@@ -33,7 +34,7 @@ import org.apache.camel.support.LifecycleStrategySupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class MainAutowiredLifecycleStrategy extends LifecycleStrategySupport implements AutowiredLifecycleStrategy {
+public class MainAutowiredLifecycleStrategy extends LifecycleStrategySupport implements AutowiredLifecycleStrategy, Ordered {
private static final Logger LOG = LoggerFactory.getLogger(MainAutowiredLifecycleStrategy.class);
@@ -51,6 +52,12 @@ public class MainAutowiredLifecycleStrategy extends LifecycleStrategySupport imp
}
@Override
+ public int getOrder() {
+ // we should be last
+ return Ordered.LOWEST;
+ }
+
+ @Override
public void onContextInitializing(CamelContext context) throws VetoCamelContextStartException {
// we have parsed configuration (such as via camel-main) and are now initializing
// so lets do autowiring on what we have collected so far