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

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


The following commit(s) were added to refs/heads/master by this push:
     new 2b3ec63eb1 [CXF-8702] If the Spring application context is creating 
the bus and has the shutdown method already wired, don't call shutdown when the 
application context is closed as that may interfere with other close events.
2b3ec63eb1 is described below

commit 2b3ec63eb1c71f9dc58cff5e6244a2dfa356340e
Author: Daniel Kulp <d...@kulp.com>
AuthorDate: Tue May 10 12:18:36 2022 -0400

    [CXF-8702] If the Spring application context is creating the bus and has 
the shutdown method already wired, don't call shutdown when the application 
context is closed as that may interfere with other close events.
---
 core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java | 13 ++++++++++++-
 core/src/main/resources/META-INF/cxf/cxf.xml                |  4 +++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java 
b/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java
index 6616c8ed85..0c625e4fc6 100644
--- a/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java
+++ b/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java
@@ -40,9 +40,18 @@ public class SpringBus extends ExtensionManagerBus
 
     AbstractApplicationContext ctx;
     boolean closeContext;
+    boolean contextLifecycleManaged;
 
     public SpringBus() {
     }
+    
+    public SpringBus(boolean ctxManaged) {
+        // if this Bus is created via the cxf.xml, then the spring context has 
the "shutdown" method
+        // already configured as a destroy method.  Thus, we should NOT call 
destroy
+        // when the context is closed as Spring will do so the rest of the 
dependencies
+        // and such are ready to be destroyed.
+        contextLifecycleManaged = ctxManaged;
+    }
 
     public void setBusConfig(BusDefinitionParser.BusConfig bc) {
         bc.setBus(this);
@@ -102,7 +111,9 @@ public class SpringBus extends ExtensionManagerBus
                 if (getState() != BusState.RUNNING) {
                     initialize();
                 }
-            } else if (event instanceof ContextClosedEvent && getState() == 
BusState.RUNNING) {
+            } else if (event instanceof ContextClosedEvent
+                && getState() == BusState.RUNNING
+                && (!contextLifecycleManaged || ctx instanceof 
BusApplicationContext)) {
                 // The bus could be create by using 
SpringBusFactory.createBus("/cxf.xml");
                 // Just to make sure the shutdown is called rightly
                 shutdown();
diff --git a/core/src/main/resources/META-INF/cxf/cxf.xml 
b/core/src/main/resources/META-INF/cxf/cxf.xml
index fb5949cd38..ed01df8b24 100644
--- a/core/src/main/resources/META-INF/cxf/cxf.xml
+++ b/core/src/main/resources/META-INF/cxf/cxf.xml
@@ -26,7 +26,9 @@
                 <bean 
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
                 <context:annotation-config/>
         -->
-    <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus" 
destroy-method="shutdown"/>
+    <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus" 
destroy-method="shutdown">
+       <constructor-arg type="boolean" value="true" />
+    </bean>
     <bean id="org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor" 
class="org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor"/>
     <bean id="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor" 
class="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor"/>
     <bean id="org.apache.cxf.bus.spring.BusExtensionPostProcessor" 
class="org.apache.cxf.bus.spring.BusExtensionPostProcessor"/>

Reply via email to