001/* 002 * Copyright 2002-2018 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 org.springframework.core.convert.converter.Converter; 020import org.springframework.format.Formatter; 021import org.springframework.format.FormatterRegistry; 022import org.springframework.http.codec.ServerCodecConfigurer; 023import org.springframework.lang.Nullable; 024import org.springframework.validation.MessageCodesResolver; 025import org.springframework.validation.Validator; 026import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder; 027import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; 028 029/** 030 * Defines callback methods to customize the configuration for WebFlux 031 * applications enabled via {@link EnableWebFlux @EnableWebFlux}. 032 * 033 * <p>{@code @EnableWebFlux}-annotated configuration classes may implement 034 * this interface to be called back and given a chance to customize the 035 * default configuration. Consider implementing this interface and 036 * overriding the relevant methods for your needs. 037 * 038 * @author Brian Clozel 039 * @author Rossen Stoyanchev 040 * @since 5.0 041 * @see WebFluxConfigurationSupport 042 * @see DelegatingWebFluxConfiguration 043 */ 044public interface WebFluxConfigurer { 045 046 /** 047 * Configure how the content type requested for the response is resolved 048 * when handling requests with annotated controllers. 049 * @param builder for configuring the resolvers to use 050 */ 051 default void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) { 052 } 053 054 /** 055 * Configure "global" cross origin request processing. 056 * <p>The configured readers and writers will apply to all requests including 057 * annotated controllers and functional endpoints. Annotated controllers can 058 * further declare more fine-grained configuration via 059 * {@link org.springframework.web.bind.annotation.CrossOrigin @CrossOrigin}. 060 * @see CorsRegistry 061 */ 062 default void addCorsMappings(CorsRegistry registry) { 063 } 064 065 /** 066 * Configure path matching options. 067 * <p>The configured path matching options will be used for mapping to 068 * annotated controllers and also 069 * {@link #addResourceHandlers(ResourceHandlerRegistry) static resources}. 070 * @param configurer the {@link PathMatchConfigurer} instance 071 */ 072 default void configurePathMatching(PathMatchConfigurer configurer) { 073 } 074 075 /** 076 * Add resource handlers for serving static resources. 077 * @see ResourceHandlerRegistry 078 */ 079 default void addResourceHandlers(ResourceHandlerRegistry registry) { 080 } 081 082 /** 083 * Configure resolvers for custom {@code @RequestMapping} method arguments. 084 * @param configurer to configurer to use 085 */ 086 default void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { 087 } 088 089 /** 090 * Configure custom HTTP message readers and writers or override built-in ones. 091 * <p>The configured readers and writers will be used for both annotated 092 * controllers and functional endpoints. 093 * @param configurer the configurer to use 094 */ 095 default void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { 096 } 097 098 /** 099 * Add custom {@link Converter Converters} and {@link Formatter Formatters} for 100 * performing type conversion and formatting of annotated controller method arguments. 101 */ 102 default void addFormatters(FormatterRegistry registry) { 103 } 104 105 /** 106 * Provide a custom {@link Validator}. 107 * <p>By default a validator for standard bean validation is created if 108 * bean validation API is present on the classpath. 109 * <p>The configured validator is used for validating annotated controller 110 * method arguments. 111 */ 112 @Nullable 113 default Validator getValidator() { 114 return null; 115 } 116 117 /** 118 * Provide a custom {@link MessageCodesResolver} to use for data binding in 119 * annotated controller method arguments instead of the one created by 120 * default in {@link org.springframework.validation.DataBinder}. 121 */ 122 @Nullable 123 default MessageCodesResolver getMessageCodesResolver() { 124 return null; 125 } 126 127 /** 128 * Configure view resolution for rendering responses with a view and a model, 129 * where the view is typically an HTML template but could also be based on 130 * an HTTP message writer (e.g. JSON, XML). 131 * <p>The configured view resolvers will be used for both annotated 132 * controllers and functional endpoints. 133 */ 134 default void configureViewResolvers(ViewResolverRegistry registry) { 135 } 136 137}