Skip to content

Commit

Permalink
Avoid bean method proxying in WebMVC and WebFlux config
Browse files Browse the repository at this point in the history
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
spring-projects/spring-framework#22596

Fixes gh-16427
  • Loading branch information
bclozel committed Apr 3, 2019
1 parent edb5937 commit f221061
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private void customizeResourceHandlerRegistration(
/**
* Configuration equivalent to {@code @EnableWebFlux}.
*/
@Configuration
@Configuration(proxyBeanMethods = false)
public static class EnableWebFluxConfiguration
extends DelegatingWebFluxConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
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;
Expand Down Expand Up @@ -466,7 +467,7 @@ static final class FaviconRequestHandler extends ResourceHttpRequestHandler {
/**
* Configuration equivalent to {@code @EnableWebMvc}.
*/
@Configuration
@Configuration(proxyBeanMethods = false)
public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration {

private final WebMvcProperties mvcProperties;
Expand All @@ -486,8 +487,12 @@ public EnableWebMvcConfiguration(

@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;
Expand All @@ -505,9 +510,13 @@ protected RequestMappingHandlerAdapter createRequestMappingHandlerAdapter() {
@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
Expand Down Expand Up @@ -539,12 +548,15 @@ protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
}

@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);
}
}

Expand All @@ -558,12 +570,9 @@ protected ExceptionHandlerExceptionResolver createExceptionHandlerExceptionResol
}

@Override
protected void configureHandlerExceptionResolvers(
protected void extendHandlerExceptionResolvers(
List<HandlerExceptionResolver> exceptionResolvers) {
super.configureHandlerExceptionResolvers(exceptionResolvers);
if (exceptionResolvers.isEmpty()) {
addDefaultHandlerExceptionResolvers(exceptionResolvers);
}
super.extendHandlerExceptionResolvers(exceptionResolvers);
if (this.mvcProperties.isLogResolvedException()) {
for (HandlerExceptionResolver resolver : exceptionResolvers) {
if (resolver instanceof AbstractHandlerExceptionResolver) {
Expand Down

0 comments on commit f221061

Please sign in to comment.