From 08740aa03d6eba58dc5122554cb8f2d0141fb8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Wed, 5 Mar 2025 08:59:49 +0100 Subject: [PATCH] Resolve WsConfigurer lazily This commit updates DelegatingWsConfiguration to resolve WsConfigurer beans, if any, lazily. Previously, those were resolved prior to the WsConfiguration would take place, leading to potential early init. Closes gh-1477 --- .../annotation/DelegatingWsConfiguration.java | 48 +++++++++++++++++-- .../annotation/WsConfigurerComposite.java | 2 + 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/spring-ws-core/src/main/java/org/springframework/ws/config/annotation/DelegatingWsConfiguration.java b/spring-ws-core/src/main/java/org/springframework/ws/config/annotation/DelegatingWsConfiguration.java index d2116be6..d84568c9 100644 --- a/spring-ws-core/src/main/java/org/springframework/ws/config/annotation/DelegatingWsConfiguration.java +++ b/spring-ws-core/src/main/java/org/springframework/ws/config/annotation/DelegatingWsConfiguration.java @@ -16,8 +16,12 @@ package org.springframework.ws.config.annotation; +import java.util.Collections; import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Stream; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.ws.server.EndpointInterceptor; @@ -25,8 +29,8 @@ import org.springframework.ws.server.endpoint.adapter.method.MethodArgumentResol import org.springframework.ws.server.endpoint.adapter.method.MethodReturnValueHandler; /** - * A sub-class of {@code WsConfigurationSupport} that detects and delegates to all beans - * of type {@link WsConfigurer} allowing them to customize the configuration provided by + * A subclass of {@code WsConfigurationSupport} that detects and delegates to all beans of + * type {@link WsConfigurer} allowing them to customize the configuration provided by * {@code WsConfigurationSupport}. This is the class actually imported by * {@link EnableWs @EnableWs}. * @@ -36,15 +40,20 @@ import org.springframework.ws.server.endpoint.adapter.method.MethodReturnValueHa @Configuration public class DelegatingWsConfiguration extends WsConfigurationSupport { - private final WsConfigurerComposite configurers = new WsConfigurerComposite(); + private WsConfigurers configurers = new WsConfigurers(Collections.emptyList()); - @Autowired(required = false) + @Deprecated(since = "4.0.12", forRemoval = true) public void setConfigurers(List configurers) { if (configurers != null && !configurers.isEmpty()) { - this.configurers.addWsConfigurers(configurers); + this.configurers = new WsConfigurers(configurers); } } + @Autowired + public void setConfigurers(ObjectProvider configurers) { + this.configurers = new WsConfigurers(configurers); + } + @Override protected void addInterceptors(List interceptors) { this.configurers.addInterceptors(interceptors); @@ -60,4 +69,33 @@ public class DelegatingWsConfiguration extends WsConfigurationSupport { this.configurers.addReturnValueHandlers(returnValueHandlers); } + private static class WsConfigurers implements WsConfigurer { + + private final Supplier> delegates; + + WsConfigurers(ObjectProvider wsConfigurers) { + this.delegates = wsConfigurers::stream; + } + + WsConfigurers(List wsConfigurers) { + this.delegates = wsConfigurers::stream; + } + + @Override + public void addInterceptors(List interceptors) { + this.delegates.get().forEach(configurer -> configurer.addInterceptors(interceptors)); + } + + @Override + public void addArgumentResolvers(List argumentResolvers) { + this.delegates.get().forEach(configurer -> configurer.addArgumentResolvers(argumentResolvers)); + } + + @Override + public void addReturnValueHandlers(List returnValueHandlers) { + this.delegates.get().forEach(configurer -> configurer.addReturnValueHandlers(returnValueHandlers)); + } + + } + } diff --git a/spring-ws-core/src/main/java/org/springframework/ws/config/annotation/WsConfigurerComposite.java b/spring-ws-core/src/main/java/org/springframework/ws/config/annotation/WsConfigurerComposite.java index 8659c8fd..bd32ad52 100644 --- a/spring-ws-core/src/main/java/org/springframework/ws/config/annotation/WsConfigurerComposite.java +++ b/spring-ws-core/src/main/java/org/springframework/ws/config/annotation/WsConfigurerComposite.java @@ -29,7 +29,9 @@ import org.springframework.ws.server.endpoint.adapter.method.MethodReturnValueHa * * @author Arjen Poutsma * @since 2.2 + * @deprecated since 4.0.12 with no replacement */ +@Deprecated(since = "4.0.12", forRemoval = true) public class WsConfigurerComposite implements WsConfigurer { private List delegates = new ArrayList<>();