[java-shib-shared] branch main updated: JSSH-71 Remove the impact of the DestructableComponent Interface
Codeberg
noreply at shibboleth.net
Wed Jul 29 17:56:05 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
https://codeberg.org/Shibboleth/java-shib-shared/commit/3e386ab03e79fd4210af8cce184c763814bf7675
The following commit(s) were added to refs/heads/main by this push:
new 3e386ab0 JSSH-71 Remove the impact of the DestructableComponent Interface
3e386ab0 is described below
commit 3e386ab03e79fd4210af8cce184c763814bf7675
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Jul 29 18:57:27 2026 +0100
JSSH-71 Remove the impact of the DestructableComponent Interface
https://shibboleth.atlassian.net/browse/JSSH-71
Refactor some code to avoid cut and paste programming
---
.../service/AbstractServiceableComponent.java | 11 +++------
.../spring/config/BeanTearDownProcessor.java | 28 +++++++++++++++-------
2 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/shib-service/src/main/java/net/shibboleth/shared/spring/service/AbstractServiceableComponent.java b/shib-service/src/main/java/net/shibboleth/shared/spring/service/AbstractServiceableComponent.java
index 9d3d1912..66d26fb1 100644
--- a/shib-service/src/main/java/net/shibboleth/shared/spring/service/AbstractServiceableComponent.java
+++ b/shib-service/src/main/java/net/shibboleth/shared/spring/service/AbstractServiceableComponent.java
@@ -30,6 +30,7 @@ import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.primitive.AnnotationsSupport;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.service.ServiceableComponent;
+import net.shibboleth.shared.spring.config.BeanTearDownProcessor;
/**
* Implementation of {@link ServiceableComponent} that does most of the work required. It leverages the spring
@@ -118,15 +119,9 @@ public abstract class AbstractServiceableComponent<T> extends AbstractIdentifiab
serviceLock.writeLock().unlock();
}
- if (null != oldContext) {
+ if (oldContext!=null) {
log.debug("Component '{}': Closing the appcontext", getId());
- // This is where the magic happens. Call the teardown on any bean with a teardown
- // method. Acts alongside the spring lifecycle
- ConfigurableListableBeanFactory clbf = oldContext.getBeanFactory();
- for (final String beanName :oldContext.getBeanDefinitionNames()) {
- final Object bean = clbf.getSingleton(beanName);
- AnnotationsSupport.callOnTeardownAnnotations(bean, beanName, log);
- }
+ BeanTearDownProcessor.tearDownBeans(oldContext);
oldContext.close();
}
// If we were not created by spring we need to do the destroy of ourself.
diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/config/BeanTearDownProcessor.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/config/BeanTearDownProcessor.java
index b8028819..bba5feb4 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/config/BeanTearDownProcessor.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/config/BeanTearDownProcessor.java
@@ -14,6 +14,7 @@
package net.shibboleth.shared.spring.config;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
@@ -37,13 +38,28 @@ import net.shibboleth.shared.primitive.LoggerFactory;
public class BeanTearDownProcessor implements ApplicationContextAware, DisposableBean {
/** Logger. */
- final private Logger log = LoggerFactory.getLogger(BeanTearDownProcessor.class);
+ final private static Logger LOG = LoggerFactory.getLogger(BeanTearDownProcessor.class);
/**
* If non null, the {@link ApplicationContext} that we were created inside.
*/
@Nullable private ApplicationContext applicationContext = null;
+ /**
+ * Given an {@link ApplicationContext}, goes through all the (non-lazy init) beans,
+ * tearing down at the annotation point
+ * @param context the context to inspect.
+ */
+ public static void tearDownBeans(@Nonnull final ApplicationContext context) {
+ if (context instanceof ConfigurableApplicationContext) {
+ final ConfigurableListableBeanFactory clbf = ((ConfigurableApplicationContext) context).getBeanFactory();
+ for (final String beanName : context.getBeanDefinitionNames()) {
+ final Object bean = clbf.getSingleton(beanName);
+ AnnotationsSupport.callOnTeardownAnnotations(bean, beanName, LOG);
+ }
+ }
+ }
+
/** {@inheritDoc}
* <p>If there is an {@link ApplicationContext} then iterate over all beans and call all
* the annotated tear down methods that each one implements (if any).</p>
@@ -54,15 +70,9 @@ public class BeanTearDownProcessor implements ApplicationContextAware, Disposabl
if (applicationContext == null) {
return;
}
-
- if (applicationContext instanceof ConfigurableApplicationContext) {
- final ConfigurableListableBeanFactory clbf = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
- for (final String beanName : applicationContext.getBeanDefinitionNames()) {
- final Object bean = clbf.getSingleton(beanName);
- AnnotationsSupport.callOnTeardownAnnotations(bean, beanName, log);
- }
- }
+ tearDownBeans(applicationContext);
}
+
/** {@inheritDoc}
* <p>We save the {@link ApplicationContext} for use in teardown.</p>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list