From f52b0b975a673b2abe4cd95f02bb7641d1e6a626 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 31 Mar 2017 11:27:09 +0100 Subject: [PATCH] Update WebFlux auto-configuration following recent API changes --- .../WebFluxAnnotationAutoConfiguration.java | 6 ++++-- .../WebFluxAnnotationAutoConfigurationTests.java | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfiguration.java index be54130382..90e1604538 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfiguration.java @@ -62,6 +62,7 @@ import org.springframework.web.reactive.resource.GzipResourceResolver; import org.springframework.web.reactive.resource.ResourceResolver; import org.springframework.web.reactive.resource.VersionResourceResolver; import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver; +import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; import org.springframework.web.reactive.result.view.ViewResolver; /** @@ -70,6 +71,7 @@ import org.springframework.web.reactive.result.view.ViewResolver; * @author Brian Clozel * @author Rob Winch * @author Stephane Nicoll + * @author Andy Wilkinson * @since 2.0.0 */ @Configuration @@ -114,9 +116,9 @@ public class WebFluxAnnotationAutoConfiguration { } @Override - public void addArgumentResolvers(List resolvers) { + public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { if (this.argumentResolvers != null) { - resolvers.addAll(this.argumentResolvers); + this.argumentResolvers.stream().forEach(configurer::addCustomResolver); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfigurationTests.java index 9150f559bc..e3d6820ec6 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAnnotationAutoConfigurationTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.web.reactive; +import java.util.List; import java.util.Optional; import javax.validation.ValidatorFactory; @@ -34,6 +35,7 @@ import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.core.io.ClassPathResource; import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.validation.Validator; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.validation.beanvalidation.SpringValidatorAdapter; @@ -59,6 +61,7 @@ import static org.mockito.Mockito.mock; * Tests for {@link WebFluxAnnotationAutoConfiguration}. * * @author Brian Clozel + * @author Andy Wilkinson */ public class WebFluxAnnotationAutoConfigurationTests { @@ -86,16 +89,19 @@ public class WebFluxAnnotationAutoConfigurationTests { .isNotNull(); } + @SuppressWarnings("unchecked") @Test public void shouldRegisterCustomHandlerMethodArgumentResolver() throws Exception { load(CustomArgumentResolvers.class); RequestMappingHandlerAdapter adapter = this.context .getBean(RequestMappingHandlerAdapter.class); - assertThat(adapter.getCustomArgumentResolvers()).contains( - this.context.getBean("firstResolver", - HandlerMethodArgumentResolver.class), - this.context.getBean("secondResolver", - HandlerMethodArgumentResolver.class)); + assertThat((List) ReflectionTestUtils + .getField(adapter.getArgumentResolverConfigurer(), "customResolvers")) + .contains( + this.context.getBean("firstResolver", + HandlerMethodArgumentResolver.class), + this.context.getBean("secondResolver", + HandlerMethodArgumentResolver.class)); } @Test