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/c0e144f9 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c0e144f9 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c0e144f9 Branch: refs/heads/camel-2.16.x Commit: c0e144f993ddba8101bec83b28d53d861d1ca4cd Parents: 7f96148 Author: msparer <msp+...@molindo.at> Authored: Tue Nov 3 12:01:14 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Nov 11 08:38:53 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/c0e144f9/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/c0e144f9/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 {