[java-shib-shared] 04/05: JSSH-71 Remove the impact of the DestructableComponent Interface
Codeberg
noreply at shibboleth.net
Tue May 26 13:21:50 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch dev/JSSH-71
in repository java-shib-shared.
View the commit online:
https://codeberg.org/Shibboleth/java-shib-shared/commit/d7cc7660564c2f1f828bee1c8af65eec5a6ac37e
commit d7cc7660564c2f1f828bee1c8af65eec5a6ac37e
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun May 24 14:02:56 2026 +0100
JSSH-71 Remove the impact of the DestructableComponent Interface
https://shibboleth.atlassian.net/browse/JSSH-71
Pivot the factory beans to using annotations (@PreDestroy),
not interfaces (Disposable/Destructable)
---
shib-networking-spring/pom.xml | 5 +++++
.../factory/FileCachingHttpClientFactoryBean.java | 15 +++++++++------
shib-spring/pom.xml | 5 +++++
.../spring/factory/AbstractComponentAwareFactoryBean.java | 13 -------------
.../shared/spring/factory/AbstractFactoryBean.java | 11 ++++++++++-
5 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/shib-networking-spring/pom.xml b/shib-networking-spring/pom.xml
index ca929317..d27d27f3 100644
--- a/shib-networking-spring/pom.xml
+++ b/shib-networking-spring/pom.xml
@@ -78,6 +78,11 @@
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
<!-- Runtime Dependencies -->
diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/FileCachingHttpClientFactoryBean.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/FileCachingHttpClientFactoryBean.java
index 99dad8ed..1554d5bf 100644
--- a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/FileCachingHttpClientFactoryBean.java
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/factory/FileCachingHttpClientFactoryBean.java
@@ -21,9 +21,10 @@ import org.apache.hc.client5.http.classic.HttpClient;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
-import net.shibboleth.shared.component.DestructableComponent;
+import jakarta.annotation.PreDestroy;
import net.shibboleth.shared.component.InitializableComponent;
import net.shibboleth.shared.httpclient.FileCachingHttpClientBuilder;
+import net.shibboleth.shared.primitive.AnnotationsSupport;
/**
* Factory bean version of {@link FileCachingHttpClientBuilder}.
@@ -48,11 +49,13 @@ public class FileCachingHttpClientFactoryBean extends FileCachingHttpClientBuild
return HttpClient.class;
}
- /** {@inheritDoc} */
- public void destroy() {
- if (singletonInstance instanceof DestructableComponent c) {
- c.destroy();
- }
+ /** {@inheritDoc}
+ *
+ * We retain the implementation of {@link DisposableBean}, but by way of
+ * belt & suspenders, we add the {@link @PreDestroy} annotation.
+ */
+ @PreDestroy public void destroy() {
+ AnnotationsSupport.callPreDestroyAnnotation(singletonInstance, null, null);
}
/** {@inheritDoc} */
diff --git a/shib-spring/pom.xml b/shib-spring/pom.xml
index 8f1bb201..fdb889e5 100644
--- a/shib-spring/pom.xml
+++ b/shib-spring/pom.xml
@@ -72,6 +72,11 @@
<artifactId>spring-webmvc</artifactId>
</dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ </dependency>
+
<!-- Provided dependencies -->
<dependency>
<groupId>jakarta.servlet</groupId>
diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/AbstractComponentAwareFactoryBean.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/AbstractComponentAwareFactoryBean.java
index ebb9f3fc..04b65c2a 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/AbstractComponentAwareFactoryBean.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/AbstractComponentAwareFactoryBean.java
@@ -18,7 +18,6 @@ import javax.annotation.Nullable;
import org.springframework.beans.factory.BeanCreationException;
-import net.shibboleth.shared.component.DestructableComponent;
import net.shibboleth.shared.component.InitializableComponent;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -39,18 +38,6 @@ public abstract class AbstractComponentAwareFactoryBean<T> extends AbstractFacto
throwIfNull = true;
}
- /**
- * {@inheritDoc}
- *
- * <p>Call our destroy method if aposite.</p>
- */
- @Override protected void destroyInstance(@Nullable final T instance) throws Exception {
- super.destroyInstance(instance);
- if (instance instanceof DestructableComponent dc) {
- dc.destroy();
- }
- }
-
/**
* Sets whether to raise an exception if a null is returned from {@link #doCreateInstance}.
*
diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/AbstractFactoryBean.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/AbstractFactoryBean.java
index 939d02a5..98271b9f 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/AbstractFactoryBean.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/factory/AbstractFactoryBean.java
@@ -37,6 +37,10 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
+import jakarta.annotation.PreDestroy;
+
+import net.shibboleth.shared.primitive.AnnotationsSupport;
+
/**
* Cloned from Spring's base class to fix bug they won't acknowledge regarding
* the ability for {@link #createInstance} to return null.
@@ -205,11 +209,15 @@ public abstract class AbstractFactoryBean<T>
/**
* Destroy the singleton instance, if any.
*
+ * To keep this aligned with the Spring original we retain
+ * the implementation of {@link DisposableBean}, but by way of belt &
+ * suspenders, we add the {@link @PreDestroy} annotation.
+ *
* {@inheritDoc}
*
* @see #destroyInstance(Object)
*/
- public void destroy() throws Exception {
+ @PreDestroy public void destroy() throws Exception {
if (isSingleton()) {
destroyInstance(this.singletonInstance);
}
@@ -267,6 +275,7 @@ public abstract class AbstractFactoryBean<T>
* @see #createInstance()
*/
protected void destroyInstance(@Nullable T instance) throws Exception {
+ AnnotationsSupport.callPreDestroyAnnotation(instance, null, null);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list