001/* 002 * Copyright 2002-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.servlet.config.annotation; 018 019import java.util.List; 020 021import org.springframework.beans.factory.annotation.Autowired; 022import org.springframework.context.annotation.Configuration; 023import org.springframework.format.FormatterRegistry; 024import org.springframework.http.converter.HttpMessageConverter; 025import org.springframework.lang.Nullable; 026import org.springframework.util.CollectionUtils; 027import org.springframework.validation.MessageCodesResolver; 028import org.springframework.validation.Validator; 029import org.springframework.web.method.support.HandlerMethodArgumentResolver; 030import org.springframework.web.method.support.HandlerMethodReturnValueHandler; 031import org.springframework.web.servlet.HandlerExceptionResolver; 032 033/** 034 * A subclass of {@code WebMvcConfigurationSupport} that detects and delegates 035 * to all beans of type {@link WebMvcConfigurer} allowing them to customize the 036 * configuration provided by {@code WebMvcConfigurationSupport}. This is the 037 * class actually imported by {@link EnableWebMvc @EnableWebMvc}. 038 * 039 * @author Rossen Stoyanchev 040 * @since 3.1 041 */ 042@Configuration(proxyBeanMethods = false) 043public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport { 044 045 private final WebMvcConfigurerComposite configurers = new WebMvcConfigurerComposite(); 046 047 048 @Autowired(required = false) 049 public void setConfigurers(List<WebMvcConfigurer> configurers) { 050 if (!CollectionUtils.isEmpty(configurers)) { 051 this.configurers.addWebMvcConfigurers(configurers); 052 } 053 } 054 055 056 @Override 057 protected void configurePathMatch(PathMatchConfigurer configurer) { 058 this.configurers.configurePathMatch(configurer); 059 } 060 061 @Override 062 protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) { 063 this.configurers.configureContentNegotiation(configurer); 064 } 065 066 @Override 067 protected void configureAsyncSupport(AsyncSupportConfigurer configurer) { 068 this.configurers.configureAsyncSupport(configurer); 069 } 070 071 @Override 072 protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { 073 this.configurers.configureDefaultServletHandling(configurer); 074 } 075 076 @Override 077 protected void addFormatters(FormatterRegistry registry) { 078 this.configurers.addFormatters(registry); 079 } 080 081 @Override 082 protected void addInterceptors(InterceptorRegistry registry) { 083 this.configurers.addInterceptors(registry); 084 } 085 086 @Override 087 protected void addResourceHandlers(ResourceHandlerRegistry registry) { 088 this.configurers.addResourceHandlers(registry); 089 } 090 091 @Override 092 protected void addCorsMappings(CorsRegistry registry) { 093 this.configurers.addCorsMappings(registry); 094 } 095 096 @Override 097 protected void addViewControllers(ViewControllerRegistry registry) { 098 this.configurers.addViewControllers(registry); 099 } 100 101 @Override 102 protected void configureViewResolvers(ViewResolverRegistry registry) { 103 this.configurers.configureViewResolvers(registry); 104 } 105 106 @Override 107 protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { 108 this.configurers.addArgumentResolvers(argumentResolvers); 109 } 110 111 @Override 112 protected void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) { 113 this.configurers.addReturnValueHandlers(returnValueHandlers); 114 } 115 116 @Override 117 protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) { 118 this.configurers.configureMessageConverters(converters); 119 } 120 121 @Override 122 protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) { 123 this.configurers.extendMessageConverters(converters); 124 } 125 126 @Override 127 protected void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) { 128 this.configurers.configureHandlerExceptionResolvers(exceptionResolvers); 129 } 130 131 @Override 132 protected void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) { 133 this.configurers.extendHandlerExceptionResolvers(exceptionResolvers); 134 } 135 136 @Override 137 @Nullable 138 protected Validator getValidator() { 139 return this.configurers.getValidator(); 140 } 141 142 @Override 143 @Nullable 144 protected MessageCodesResolver getMessageCodesResolver() { 145 return this.configurers.getMessageCodesResolver(); 146 } 147 148}