From f221061d81dc0250e950ca7251d7182652d2e46d Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Wed, 3 Apr 2019 11:28:38 +0200 Subject: [PATCH] Avoid bean method proxying in WebMVC and WebFlux config This commit applies changes similar to what's been done in gh-9068, for MVC and WebFlux configurations. This is now possible thanks to the changes done in Spring Framework in https://github.com/spring-projects/spring-framework/pull/22596 Fixes gh-16427 --- .../reactive/WebFluxAutoConfiguration.java | 2 +- .../web/servlet/WebMvcAutoConfiguration.java | 33 ++++++++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java index 1ea91f945d..b80e28fbe4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java @@ -211,7 +211,7 @@ public class WebFluxAutoConfiguration { /** * Configuration equivalent to {@code @EnableWebFlux}. */ - @Configuration + @Configuration(proxyBeanMethods = false) public static class EnableWebFluxConfiguration extends DelegatingWebFluxConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java index c2511c61cf..cbda523fa8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java @@ -119,6 +119,7 @@ import org.springframework.web.servlet.resource.AppCacheManifestTransformer; import org.springframework.web.servlet.resource.EncodedResourceResolver; import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; import org.springframework.web.servlet.resource.ResourceResolver; +import org.springframework.web.servlet.resource.ResourceUrlProvider; import org.springframework.web.servlet.resource.VersionResourceResolver; import org.springframework.web.servlet.view.BeanNameViewResolver; import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; @@ -466,7 +467,7 @@ public class WebMvcAutoConfiguration { /** * Configuration equivalent to {@code @EnableWebMvc}. */ - @Configuration + @Configuration(proxyBeanMethods = false) public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration { private final WebMvcProperties mvcProperties; @@ -486,8 +487,12 @@ public class WebMvcAutoConfiguration { @Bean @Override - public RequestMappingHandlerAdapter requestMappingHandlerAdapter() { - RequestMappingHandlerAdapter adapter = super.requestMappingHandlerAdapter(); + public RequestMappingHandlerAdapter requestMappingHandlerAdapter( + ContentNegotiationManager mvcContentNegotiationManager, + FormattingConversionService mvcConversionService, + Validator mvcValidator) { + RequestMappingHandlerAdapter adapter = super.requestMappingHandlerAdapter( + mvcContentNegotiationManager, mvcConversionService, mvcValidator); adapter.setIgnoreDefaultModelOnRedirect(this.mvcProperties == null || this.mvcProperties.isIgnoreDefaultModelOnRedirect()); return adapter; @@ -505,9 +510,13 @@ public class WebMvcAutoConfiguration { @Bean @Primary @Override - public RequestMappingHandlerMapping requestMappingHandlerMapping() { + public RequestMappingHandlerMapping requestMappingHandlerMapping( + ContentNegotiationManager mvcContentNegotiationManager, + FormattingConversionService mvcConversionService, + ResourceUrlProvider mvcResourceUrlProvider) { // Must be @Primary for MvcUriComponentsBuilder to work - return super.requestMappingHandlerMapping(); + return super.requestMappingHandlerMapping(mvcContentNegotiationManager, + mvcConversionService, mvcResourceUrlProvider); } @Bean @@ -539,12 +548,15 @@ public class WebMvcAutoConfiguration { } @Override - protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer() { + protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer( + FormattingConversionService mvcConversionService, + Validator mvcValidator) { try { return this.beanFactory.getBean(ConfigurableWebBindingInitializer.class); } catch (NoSuchBeanDefinitionException ex) { - return super.getConfigurableWebBindingInitializer(); + return super.getConfigurableWebBindingInitializer(mvcConversionService, + mvcValidator); } } @@ -558,12 +570,9 @@ public class WebMvcAutoConfiguration { } @Override - protected void configureHandlerExceptionResolvers( + protected void extendHandlerExceptionResolvers( List exceptionResolvers) { - super.configureHandlerExceptionResolvers(exceptionResolvers); - if (exceptionResolvers.isEmpty()) { - addDefaultHandlerExceptionResolvers(exceptionResolvers); - } + super.extendHandlerExceptionResolvers(exceptionResolvers); if (this.mvcProperties.isLogResolvedException()) { for (HandlerExceptionResolver resolver : exceptionResolvers) { if (resolver instanceof AbstractHandlerExceptionResolver) {