001/* 002 * Copyright 2002-2020 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.reactive.config; 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.codec.ServerCodecConfigurer; 025import org.springframework.util.CollectionUtils; 026import org.springframework.validation.MessageCodesResolver; 027import org.springframework.validation.Validator; 028import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder; 029import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; 030 031/** 032 * A subclass of {@code WebFluxConfigurationSupport} that detects and delegates 033 * to all beans of type {@link WebFluxConfigurer} allowing them to customize the 034 * configuration provided by {@code WebFluxConfigurationSupport}. This is the 035 * class actually imported by {@link EnableWebFlux @EnableWebFlux}. 036 * 037 * @author Brian Clozel 038 * @since 5.0 039 */ 040@Configuration(proxyBeanMethods = false) 041public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport { 042 043 private final WebFluxConfigurerComposite configurers = new WebFluxConfigurerComposite(); 044 045 046 @Autowired(required = false) 047 public void setConfigurers(List<WebFluxConfigurer> configurers) { 048 if (!CollectionUtils.isEmpty(configurers)) { 049 this.configurers.addWebFluxConfigurers(configurers); 050 } 051 } 052 053 054 @Override 055 protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) { 056 this.configurers.configureContentTypeResolver(builder); 057 } 058 059 @Override 060 protected void addCorsMappings(CorsRegistry registry) { 061 this.configurers.addCorsMappings(registry); 062 } 063 064 @Override 065 public void configurePathMatching(PathMatchConfigurer configurer) { 066 this.configurers.configurePathMatching(configurer); 067 } 068 069 @Override 070 protected void addResourceHandlers(ResourceHandlerRegistry registry) { 071 this.configurers.addResourceHandlers(registry); 072 } 073 074 @Override 075 protected void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { 076 this.configurers.configureArgumentResolvers(configurer); 077 } 078 079 @Override 080 protected void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { 081 this.configurers.configureHttpMessageCodecs(configurer); 082 } 083 084 @Override 085 protected void addFormatters(FormatterRegistry registry) { 086 this.configurers.addFormatters(registry); 087 } 088 089 @Override 090 protected Validator getValidator() { 091 Validator validator = this.configurers.getValidator(); 092 return (validator != null ? validator : super.getValidator()); 093 } 094 095 @Override 096 protected MessageCodesResolver getMessageCodesResolver() { 097 MessageCodesResolver messageCodesResolver = this.configurers.getMessageCodesResolver(); 098 return (messageCodesResolver != null ? messageCodesResolver : super.getMessageCodesResolver()); 099 } 100 101 @Override 102 protected void configureViewResolvers(ViewResolverRegistry registry) { 103 this.configurers.configureViewResolvers(registry); 104 } 105 106}