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 10:49:53 UTC
(camel) branch main updated: CAMEL-24182: Fix SpringBusFactoryBean to shut down bus on context close
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 95386a10afa2 CAMEL-24182: Fix SpringBusFactoryBean to shut down bus on context close
95386a10afa2 is described below
commit 95386a10afa2bcbeeaa5f37aa5f2be4bdf683f3f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Jul 20 12:49:46 2026 +0200
CAMEL-24182: Fix SpringBusFactoryBean to shut down bus on context close
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.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;
+ }
+
}