Skip to content

Commit 08740aa

Browse files
committed
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
1 parent a395d82 commit 08740aa

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

spring-ws-core/src/main/java/org/springframework/ws/config/annotation/DelegatingWsConfiguration.java

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616

1717
package org.springframework.ws.config.annotation;
1818

19+
import java.util.Collections;
1920
import java.util.List;
21+
import java.util.function.Supplier;
22+
import java.util.stream.Stream;
2023

24+
import org.springframework.beans.factory.ObjectProvider;
2125
import org.springframework.beans.factory.annotation.Autowired;
2226
import org.springframework.context.annotation.Configuration;
2327
import org.springframework.ws.server.EndpointInterceptor;
2428
import org.springframework.ws.server.endpoint.adapter.method.MethodArgumentResolver;
2529
import org.springframework.ws.server.endpoint.adapter.method.MethodReturnValueHandler;
2630

2731
/**
28-
* A sub-class of {@code WsConfigurationSupport} that detects and delegates to all beans
29-
* of type {@link WsConfigurer} allowing them to customize the configuration provided by
32+
* A subclass of {@code WsConfigurationSupport} that detects and delegates to all beans of
33+
* type {@link WsConfigurer} allowing them to customize the configuration provided by
3034
* {@code WsConfigurationSupport}. This is the class actually imported by
3135
* {@link EnableWs @EnableWs}.
3236
*
@@ -36,15 +40,20 @@
3640
@Configuration
3741
public class DelegatingWsConfiguration extends WsConfigurationSupport {
3842

39-
private final WsConfigurerComposite configurers = new WsConfigurerComposite();
43+
private WsConfigurers configurers = new WsConfigurers(Collections.emptyList());
4044

41-
@Autowired(required = false)
45+
@Deprecated(since = "4.0.12", forRemoval = true)
4246
public void setConfigurers(List<WsConfigurer> configurers) {
4347
if (configurers != null && !configurers.isEmpty()) {
44-
this.configurers.addWsConfigurers(configurers);
48+
this.configurers = new WsConfigurers(configurers);
4549
}
4650
}
4751

52+
@Autowired
53+
public void setConfigurers(ObjectProvider<WsConfigurer> configurers) {
54+
this.configurers = new WsConfigurers(configurers);
55+
}
56+
4857
@Override
4958
protected void addInterceptors(List<EndpointInterceptor> interceptors) {
5059
this.configurers.addInterceptors(interceptors);
@@ -60,4 +69,33 @@ protected void addReturnValueHandlers(List<MethodReturnValueHandler> returnValue
6069
this.configurers.addReturnValueHandlers(returnValueHandlers);
6170
}
6271

72+
private static class WsConfigurers implements WsConfigurer {
73+
74+
private final Supplier<Stream<WsConfigurer>> delegates;
75+
76+
WsConfigurers(ObjectProvider<WsConfigurer> wsConfigurers) {
77+
this.delegates = wsConfigurers::stream;
78+
}
79+
80+
WsConfigurers(List<WsConfigurer> wsConfigurers) {
81+
this.delegates = wsConfigurers::stream;
82+
}
83+
84+
@Override
85+
public void addInterceptors(List<EndpointInterceptor> interceptors) {
86+
this.delegates.get().forEach(configurer -> configurer.addInterceptors(interceptors));
87+
}
88+
89+
@Override
90+
public void addArgumentResolvers(List<MethodArgumentResolver> argumentResolvers) {
91+
this.delegates.get().forEach(configurer -> configurer.addArgumentResolvers(argumentResolvers));
92+
}
93+
94+
@Override
95+
public void addReturnValueHandlers(List<MethodReturnValueHandler> returnValueHandlers) {
96+
this.delegates.get().forEach(configurer -> configurer.addReturnValueHandlers(returnValueHandlers));
97+
}
98+
99+
}
100+
63101
}

spring-ws-core/src/main/java/org/springframework/ws/config/annotation/WsConfigurerComposite.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
*
3030
* @author Arjen Poutsma
3131
* @since 2.2
32+
* @deprecated since 4.0.12 with no replacement
3233
*/
34+
@Deprecated(since = "4.0.12", forRemoval = true)
3335
public class WsConfigurerComposite implements WsConfigurer {
3436

3537
private List<WsConfigurer> delegates = new ArrayList<>();

0 commit comments

Comments
 (0)