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 2026/07/20 09:17:32 UTC

(camel) branch fix/CAMEL-24182 created (now a7cc59f3f7fd)

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

davsclaus pushed a change to branch fix/CAMEL-24182
in repository https://gitbox.apache.org/repos/asf/camel.git


      at a7cc59f3f7fd CAMEL-24182: Fix SpringBusFactoryBean to shut down bus on context close

This branch includes the following new commits:

     new a7cc59f3f7fd CAMEL-24182: Fix SpringBusFactoryBean to shut down bus on context close

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-24182: Fix SpringBusFactoryBean to shut down bus on context close

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch fix/CAMEL-24182
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a7cc59f3f7fddb457d4c39c062c8ad9f172823d7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Jul 20 11:17:19 2026 +0200

    CAMEL-24182: Fix SpringBusFactoryBean to shut down bus on context close
    
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
    Signed-off-by: Claus Ibsen <cl...@gmail.com>
---
 .../component/cxf/spring/SpringBusFactoryBean.java | 29 ++++++++++++++++------
 .../cxf/spring/SpringBusFactoryBeanTest.java       | 19 ++++++++++++++
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/components/camel-cxf/camel-cxf-spring-common/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java b/components/camel-cxf/camel-cxf-spring-common/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java
index 9895e66d1dc8..66ed6b9400dc 100644
--- a/components/camel-cxf/camel-cxf-spring-common/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java
+++ b/components/camel-cxf/camel-cxf-spring-common/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.cxf.spring;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.SmartFactoryBean;
 
 /**
@@ -29,18 +30,22 @@ import org.springframework.beans.factory.SmartFactoryBean;
  * all the extension in CXF 2.4.x by default. You can still specify the spring extension file in the cfgFiles list and
  * it will override the extensions which is load by CXF bus.
  */
-public class SpringBusFactoryBean implements SmartFactoryBean<Bus> {
+public class SpringBusFactoryBean implements SmartFactoryBean<Bus>, DisposableBean {
     private String[] cfgFiles;
     private boolean includeDefaultBus;
+    private Bus bus;
 
     @Override
     public Bus getObject() throws Exception {
-        SpringBusFactory bf = new SpringBusFactory();
-        if (cfgFiles != null) {
-            return bf.createBus(cfgFiles, includeDefaultBus);
-        } else {
-            return bf.createBus();
+        if (bus == null) {
+            SpringBusFactory bf = new SpringBusFactory();
+            if (cfgFiles != null) {
+                bus = bf.createBus(cfgFiles, includeDefaultBus);
+            } else {
+                bus = bf.createBus();
+            }
         }
+        return bus;
     }
 
     @Override
@@ -49,7 +54,9 @@ public class SpringBusFactoryBean implements SmartFactoryBean<Bus> {
     }
 
     public void setCfgFiles(String cfgFiles) {
-        this.cfgFiles = cfgFiles.split(";");
+        if (cfgFiles != null) {
+            this.cfgFiles = cfgFiles.split(";");
+        }
     }
 
     public void setIncludeDefaultBus(boolean includeDefaultBus) {
@@ -71,4 +78,12 @@ public class SpringBusFactoryBean implements SmartFactoryBean<Bus> {
         return false;
     }
 
+    @Override
+    public void destroy() {
+        if (bus != null) {
+            bus.shutdown(true);
+            bus = null;
+        }
+    }
+
 }
diff --git a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBeanTest.java b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBeanTest.java
index 05367810d8ba..7e706f864182 100644
--- a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBeanTest.java
+++ b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBeanTest.java
@@ -17,9 +17,11 @@
 package org.apache.camel.component.cxf.spring;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.Bus.BusState;
 import org.apache.cxf.binding.soap.SoapBindingFactory;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 public class SpringBusFactoryBeanTest extends AbstractSpringBeanTestSupport {
@@ -41,4 +43,21 @@ public class SpringBusFactoryBeanTest extends AbstractSpringBeanTestSupport {
         assertNotNull(soapBindingFactory, "You should find the factory here");
     }
 
+    @Test
+    public void testBusShutdownOnContextClose() {
+        Bus bus = ctx.getBean("cxfBus", Bus.class);
+        assertNotNull(bus);
+
+        // bus should be running while context is open
+        assertEquals(BusState.RUNNING, bus.getState());
+
+        // closing the context must shut down the bus via DisposableBean.destroy()
+        ctx.close();
+        assertEquals(BusState.SHUTDOWN, bus.getState(),
+                "Bus must be shut down after application context close");
+
+        // prevent tearDown from closing again
+        ctx = null;
+    }
+
 }