Skip to content

Commit 3c887f6

Browse files
committed
Avoid reflection in SpringDataWebConfiguration.
We now use an explicit lookup via the application context to consume PageableHandlerMethodArgumentResolverCustomizer and SortHandlerMethodArgumentResolverCustomizer rather than autowiring those into a field. Fixes #2440.
1 parent 4acd3b7 commit 3c887f6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Diff for: src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
package org.springframework.data.web.config;
1717

1818
import java.util.List;
19-
import java.util.Optional;
2019

2120
import org.springframework.beans.factory.BeanClassLoaderAware;
2221
import org.springframework.beans.factory.ObjectFactory;
23-
import org.springframework.beans.factory.annotation.Autowired;
2422
import org.springframework.beans.factory.annotation.Qualifier;
2523
import org.springframework.context.ApplicationContext;
2624
import org.springframework.context.annotation.Bean;
@@ -66,9 +64,8 @@ public class SpringDataWebConfiguration implements WebMvcConfigurer, BeanClassLo
6664

6765
private final Lazy<SortHandlerMethodArgumentResolver> sortResolver;
6866
private final Lazy<PageableHandlerMethodArgumentResolver> pageableResolver;
69-
70-
private @Autowired Optional<PageableHandlerMethodArgumentResolverCustomizer> pageableResolverCustomizer;
71-
private @Autowired Optional<SortHandlerMethodArgumentResolverCustomizer> sortResolverCustomizer;
67+
private final Lazy<PageableHandlerMethodArgumentResolverCustomizer> pageableResolverCustomizer;
68+
private final Lazy<SortHandlerMethodArgumentResolverCustomizer> sortResolverCustomizer;
7269

7370
public SpringDataWebConfiguration(ApplicationContext context,
7471
@Qualifier("mvcConversionService") ObjectFactory<ConversionService> conversionService) {
@@ -77,10 +74,15 @@ public SpringDataWebConfiguration(ApplicationContext context,
7774
Assert.notNull(conversionService, "ConversionService must not be null!");
7875

7976
this.context = context;
77+
8078
this.conversionService = conversionService;
8179
this.sortResolver = Lazy.of(() -> context.getBean("sortResolver", SortHandlerMethodArgumentResolver.class));
82-
this.pageableResolver = Lazy
83-
.of(() -> context.getBean("pageableResolver", PageableHandlerMethodArgumentResolver.class));
80+
this.pageableResolver = Lazy.of( //
81+
() -> context.getBean("pageableResolver", PageableHandlerMethodArgumentResolver.class));
82+
this.pageableResolverCustomizer = Lazy.of( //
83+
() -> context.getBeanProvider(PageableHandlerMethodArgumentResolverCustomizer.class).getIfAvailable());
84+
this.sortResolverCustomizer = Lazy.of( //
85+
() -> context.getBeanProvider(SortHandlerMethodArgumentResolverCustomizer.class).getIfAvailable());
8486
}
8587

8688
/*
@@ -181,11 +183,11 @@ public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
181183
}
182184

183185
protected void customizePageableResolver(PageableHandlerMethodArgumentResolver pageableResolver) {
184-
pageableResolverCustomizer.ifPresent(c -> c.customize(pageableResolver));
186+
pageableResolverCustomizer.getOptional().ifPresent(c -> c.customize(pageableResolver));
185187
}
186188

187189
protected void customizeSortResolver(SortHandlerMethodArgumentResolver sortResolver) {
188-
sortResolverCustomizer.ifPresent(c -> c.customize(sortResolver));
190+
sortResolverCustomizer.getOptional().ifPresent(c -> c.customize(sortResolver));
189191
}
190192

191193
private void forwardBeanClassLoader(BeanClassLoaderAware target) {

0 commit comments

Comments
 (0)