001/*
002 * Copyright 2002-2016 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.util.CollectionUtils;
026import org.springframework.validation.MessageCodesResolver;
027import org.springframework.validation.Validator;
028import org.springframework.web.method.support.HandlerMethodArgumentResolver;
029import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
030import org.springframework.web.servlet.HandlerExceptionResolver;
031
032/**
033 * A subclass of {@code WebMvcConfigurationSupport} that detects and delegates
034 * to all beans of type {@link WebMvcConfigurer} allowing them to customize the
035 * configuration provided by {@code WebMvcConfigurationSupport}. This is the
036 * class actually imported by {@link EnableWebMvc @EnableWebMvc}.
037 *
038 * @author Rossen Stoyanchev
039 * @since 3.1
040 */
041@Configuration
042public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {
043
044        private final WebMvcConfigurerComposite configurers = new WebMvcConfigurerComposite();
045
046
047        @Autowired(required = false)
048        public void setConfigurers(List<WebMvcConfigurer> configurers) {
049                if (!CollectionUtils.isEmpty(configurers)) {
050                        this.configurers.addWebMvcConfigurers(configurers);
051                }
052        }
053
054
055        @Override
056        protected void configurePathMatch(PathMatchConfigurer configurer) {
057                this.configurers.configurePathMatch(configurer);
058        }
059
060        @Override
061        protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
062                this.configurers.configureContentNegotiation(configurer);
063        }
064
065        @Override
066        protected void configureAsyncSupport(AsyncSupportConfigurer configurer) {
067                this.configurers.configureAsyncSupport(configurer);
068        }
069
070        @Override
071        protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
072                this.configurers.configureDefaultServletHandling(configurer);
073        }
074
075        @Override
076        protected void addFormatters(FormatterRegistry registry) {
077                this.configurers.addFormatters(registry);
078        }
079
080        @Override
081        protected void addInterceptors(InterceptorRegistry registry) {
082                this.configurers.addInterceptors(registry);
083        }
084
085        @Override
086        protected void addResourceHandlers(ResourceHandlerRegistry registry) {
087                this.configurers.addResourceHandlers(registry);
088        }
089
090        @Override
091        protected void addCorsMappings(CorsRegistry registry) {
092                this.configurers.addCorsMappings(registry);
093        }
094
095        @Override
096        protected void addViewControllers(ViewControllerRegistry registry) {
097                this.configurers.addViewControllers(registry);
098        }
099
100        @Override
101        protected void configureViewResolvers(ViewResolverRegistry registry) {
102                this.configurers.configureViewResolvers(registry);
103        }
104
105        @Override
106        protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
107                this.configurers.addArgumentResolvers(argumentResolvers);
108        }
109
110        @Override
111        protected void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
112                this.configurers.addReturnValueHandlers(returnValueHandlers);
113        }
114
115        @Override
116        protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
117                this.configurers.configureMessageConverters(converters);
118        }
119
120        @Override
121        protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
122                this.configurers.extendMessageConverters(converters);
123        }
124
125        @Override
126        protected void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
127                this.configurers.configureHandlerExceptionResolvers(exceptionResolvers);
128        }
129
130        @Override
131        protected void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
132                this.configurers.extendHandlerExceptionResolvers(exceptionResolvers);
133        }
134
135        @Override
136        protected Validator getValidator() {
137                return this.configurers.getValidator();
138        }
139
140        @Override
141        protected MessageCodesResolver getMessageCodesResolver() {
142                return this.configurers.getMessageCodesResolver();
143        }
144
145}