Repository: camel Updated Branches: refs/heads/camel-2.15.x 27a9b3953 -> 5d266ce2c refs/heads/camel-2.16.x 7f961480a -> c73de90d2 refs/heads/master ba84da4ab -> 0589a1490
adapted the changes of CAMEL-8460 to only refresh routes on ContextRefreshEvents from "own" applicationContext. Previously route refreshs were initiated only if the parent applicationContext of the event's context was null. This doesn't work when Spring instantiates the Camel's application context as child of another applicationContext. This e.g. happens as soon as you're using spring-cloud-config Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/66b6edcf Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/66b6edcf Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/66b6edcf Branch: refs/heads/master Commit: 66b6edcf2706eb9b4911967c33a8d6a9c4528747 Parents: ba84da4 Author: msparer <[email protected]> Authored: Tue Nov 3 12:01:14 2015 +0100 Committer: Claus Ibsen <[email protected]> Committed: Wed Nov 11 08:35:32 2015 +0100 ---------------------------------------------------------------------- .../camel/spring/boot/CamelAutoConfiguration.java | 2 +- .../org/apache/camel/spring/boot/RoutesCollector.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/66b6edcf/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java index 9034f09..e1bd003 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java @@ -69,7 +69,7 @@ public class CamelAutoConfiguration { @ConditionalOnMissingBean(RoutesCollector.class) RoutesCollector routesCollector(ApplicationContext applicationContext) { Collection<CamelContextConfiguration> configurations = applicationContext.getBeansOfType(CamelContextConfiguration.class).values(); - return new RoutesCollector(new ArrayList<CamelContextConfiguration>(configurations)); + return new RoutesCollector(applicationContext, new ArrayList<CamelContextConfiguration>(configurations)); } /** http://git-wip-us.apache.org/repos/asf/camel/blob/66b6edcf/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java index 33d479b..cf6ea40 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.camel.CamelContext; import org.apache.camel.RoutesBuilder; -import org.apache.camel.ServiceStatus; import org.apache.camel.model.RoutesDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,12 +41,15 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven private static final Logger LOG = LoggerFactory.getLogger(RoutesCollector.class); // Collaborators + + private final ApplicationContext applicationContext; private final List<CamelContextConfiguration> camelContextConfigurations; // Constructors - public RoutesCollector(List<CamelContextConfiguration> camelContextConfigurations) { + public RoutesCollector(ApplicationContext applicationContext, List<CamelContextConfiguration> camelContextConfigurations) { + this.applicationContext = applicationContext; this.camelContextConfigurations = new ArrayList<CamelContextConfiguration>(camelContextConfigurations); } @@ -56,9 +58,9 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven @Override public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext(); - CamelContext camelContext = contextRefreshedEvent.getApplicationContext().getBean(CamelContext.class); - // if we have not yet started - if (camelContext.getStatus() == ServiceStatus.Stopped) { + // only listen to context refreshs of "my" applicationContext + if (this.applicationContext.equals(applicationContext)) { + CamelContext camelContext = contextRefreshedEvent.getApplicationContext().getBean(CamelContext.class); LOG.debug("Post-processing CamelContext bean: {}", camelContext.getName()); for (RoutesBuilder routesBuilder : applicationContext.getBeansOfType(RoutesBuilder.class).values()) { try {
