You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2018/10/29 11:00:22 UTC

[camel] 01/04: CAMEL-12905: The trigger that starts the SpringCamelContext and that collect to routes to the camel context, needs to be a ContextRefreshedEvent that has been emitted by the ApplicationContext that instantiated the SpringCamelContext instance.

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

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

commit 738476cc101de0728d61067dee51c9e94baa444c
Author: Omar Alles <oa...@gmail.com>
AuthorDate: Fri Oct 26 23:54:13 2018 +0200

    CAMEL-12905: The trigger that starts the SpringCamelContext and that collect to routes to the camel context, needs to be a ContextRefreshedEvent that has been emitted by the ApplicationContext that instantiated the SpringCamelContext instance.
---
 .../src/main/java/org/apache/camel/spring/boot/RoutesCollector.java    | 3 ++-
 .../src/main/java/org/apache/camel/spring/SpringCamelContext.java      | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

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 54f2064..42167cf 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
@@ -84,7 +84,8 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
         CamelContext camelContext = applicationContext.getBean(CamelContext.class);
 
         // only add and start Camel if its stopped (initial state)
-        if (camelContext.getStatus().isStopped()) {
+        if (((ContextRefreshedEvent) event).getApplicationContext().getId().equals(this.applicationContext.getId())
+                && camelContext.getStatus().isStopped()) {
             LOG.debug("Post-processing CamelContext bean: {}", camelContext.getName());
 
             final AntPathMatcher matcher = new AntPathMatcher();
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java b/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
index e32e581..711cbe3 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
@@ -159,7 +159,7 @@ public class SpringCamelContext extends DefaultCamelContext implements Lifecycle
     public void onApplicationEvent(ApplicationEvent event) {
         LOG.debug("onApplicationEvent: {}", event);
 
-        if (event instanceof ContextRefreshedEvent) {
+        if (event instanceof ContextRefreshedEvent && ((ContextRefreshedEvent) event).getApplicationContext().getId().equals(this.applicationContext.getId())) {
             // nominally we would prefer to use Lifecycle interface that
             // would invoke start() method, but in order to do that 
             // SpringCamelContext needs to implement SmartLifecycle