Skip to content

Commit

Permalink
Resolve WsConfigurer lazily
Browse files Browse the repository at this point in the history
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
  • Loading branch information
snicoll committed Mar 5, 2025
1 parent a395d82 commit 08740aa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@

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;
import org.springframework.ws.server.endpoint.adapter.method.MethodArgumentResolver;
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}.
*
Expand All @@ -36,15 +40,20 @@
@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<WsConfigurer> configurers) {
if (configurers != null && !configurers.isEmpty()) {
this.configurers.addWsConfigurers(configurers);
this.configurers = new WsConfigurers(configurers);
}
}

@Autowired
public void setConfigurers(ObjectProvider<WsConfigurer> configurers) {
this.configurers = new WsConfigurers(configurers);
}

@Override
protected void addInterceptors(List<EndpointInterceptor> interceptors) {
this.configurers.addInterceptors(interceptors);
Expand All @@ -60,4 +69,33 @@ protected void addReturnValueHandlers(List<MethodReturnValueHandler> returnValue
this.configurers.addReturnValueHandlers(returnValueHandlers);
}

private static class WsConfigurers implements WsConfigurer {

private final Supplier<Stream<WsConfigurer>> delegates;

WsConfigurers(ObjectProvider<WsConfigurer> wsConfigurers) {
this.delegates = wsConfigurers::stream;
}

WsConfigurers(List<WsConfigurer> wsConfigurers) {
this.delegates = wsConfigurers::stream;
}

@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
this.delegates.get().forEach(configurer -> configurer.addInterceptors(interceptors));
}

@Override
public void addArgumentResolvers(List<MethodArgumentResolver> argumentResolvers) {
this.delegates.get().forEach(configurer -> configurer.addArgumentResolvers(argumentResolvers));
}

@Override
public void addReturnValueHandlers(List<MethodReturnValueHandler> returnValueHandlers) {
this.delegates.get().forEach(configurer -> configurer.addReturnValueHandlers(returnValueHandlers));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
*
* @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<WsConfigurer> delegates = new ArrayList<>();
Expand Down

0 comments on commit 08740aa

Please sign in to comment.