diff --git a/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java b/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java index bebbaea32..ad1ab33c5 100644 --- a/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java +++ b/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java @@ -16,11 +16,9 @@ package org.springframework.data.web.config; import java.util.List; -import java.util.Optional; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.ObjectFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -66,9 +64,8 @@ public class SpringDataWebConfiguration implements WebMvcConfigurer, BeanClassLo private final Lazy sortResolver; private final Lazy pageableResolver; - - private @Autowired Optional pageableResolverCustomizer; - private @Autowired Optional sortResolverCustomizer; + private final Lazy pageableResolverCustomizer; + private final Lazy sortResolverCustomizer; public SpringDataWebConfiguration(ApplicationContext context, @Qualifier("mvcConversionService") ObjectFactory conversionService) { @@ -77,10 +74,15 @@ public class SpringDataWebConfiguration implements WebMvcConfigurer, BeanClassLo Assert.notNull(conversionService, "ConversionService must not be null!"); this.context = context; + this.conversionService = conversionService; this.sortResolver = Lazy.of(() -> context.getBean("sortResolver", SortHandlerMethodArgumentResolver.class)); - this.pageableResolver = Lazy - .of(() -> context.getBean("pageableResolver", PageableHandlerMethodArgumentResolver.class)); + this.pageableResolver = Lazy.of( // + () -> context.getBean("pageableResolver", PageableHandlerMethodArgumentResolver.class)); + this.pageableResolverCustomizer = Lazy.of( // + () -> context.getBeanProvider(PageableHandlerMethodArgumentResolverCustomizer.class).getIfAvailable()); + this.sortResolverCustomizer = Lazy.of( // + () -> context.getBeanProvider(SortHandlerMethodArgumentResolverCustomizer.class).getIfAvailable()); } /* @@ -181,11 +183,11 @@ public class SpringDataWebConfiguration implements WebMvcConfigurer, BeanClassLo } protected void customizePageableResolver(PageableHandlerMethodArgumentResolver pageableResolver) { - pageableResolverCustomizer.ifPresent(c -> c.customize(pageableResolver)); + pageableResolverCustomizer.getOptional().ifPresent(c -> c.customize(pageableResolver)); } protected void customizeSortResolver(SortHandlerMethodArgumentResolver sortResolver) { - sortResolverCustomizer.ifPresent(c -> c.customize(sortResolver)); + sortResolverCustomizer.getOptional().ifPresent(c -> c.customize(sortResolver)); } private void forwardBeanClassLoader(BeanClassLoaderAware target) {