diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfiguration.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfiguration.java index bfc3a7ac3de..6be4d79fc74 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfiguration.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfiguration.java @@ -51,8 +51,8 @@ public class DelegatingWebReactiveConfiguration extends WebReactiveConfiguration } @Override - protected void configureRequestedContentTypeResolver(RequestedContentTypeResolverBuilder builder) { - this.configurers.configureRequestedContentTypeResolver(builder); + protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) { + this.configurers.configureContentTypeResolver(builder); } @Override diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/EnableWebReactive.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/EnableWebReactive.java index ed55479e151..dd84b554774 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/EnableWebReactive.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/EnableWebReactive.java @@ -31,19 +31,19 @@ import org.springframework.context.annotation.Import; *
* @Configuration
* @EnableWebReactive
- * @ComponentScan(basePackageClasses = { MyConfiguration.class })
- * public class MyWebConfiguration {
+ * @ComponentScan(basePackageClasses = MyConfiguration.class)
+ * public class MyConfiguration {
*
* }
*
*
- * To customize the imported configuration, implement the interface - * {@link WebReactiveConfigurer} and override individual methods, e.g.: + *
To customize the imported configuration implement + * {@link WebReactiveConfigurer} and override individual methods as shown below: * *
* @Configuration
- * @EnableWebMvc
- * @ComponentScan(basePackageClasses = { MyConfiguration.class })
+ * @EnableWebReactive
+ * @ComponentScan(basePackageClasses = MyConfiguration.class)
* public class MyConfiguration implements WebReactiveConfigurer {
*
* @Override
@@ -56,17 +56,23 @@ import org.springframework.context.annotation.Import;
* messageWriters.add(new MyHttpMessageWriter());
* }
*
- * // More overridden methods ...
* }
*
*
- * If {@link WebReactiveConfigurer} does not expose some advanced setting that - * needs to be configured, consider removing the {@code @EnableWebReactive} + *
Note: only one {@code @Configuration} class may have the + * {@code @EnableWebReactive} annotation to import the Spring Web Reactive + * configuration. There can however be multiple {@code @Configuration} classes + * implementing {@code WebReactiveConfigurer} in order to customize the provided + * configuration. + * + *
If {@link WebReactiveConfigurer} does not expose some more advanced setting
+ * that needs to be configured consider removing the {@code @EnableWebReactive}
* annotation and extending directly from {@link WebReactiveConfigurationSupport}
* or {@link DelegatingWebReactiveConfiguration} if you still want to allow
* {@link WebReactiveConfigurer} instances to customize the configuration.
*
* @author Brian Clozel
+ * @author Rossen Stoyanchev
* @since 5.0
* @see WebReactiveConfigurer
* @see WebReactiveConfigurationSupport
diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfigurationSupport.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfigurationSupport.java
index 342109f7fdc..ec6c3ff9044 100644
--- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfigurationSupport.java
+++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfigurationSupport.java
@@ -167,7 +167,7 @@ public class WebReactiveConfigurationSupport implements ApplicationContextAware
public CompositeContentTypeResolver webReactiveContentTypeResolver() {
RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder();
builder.mediaTypes(getDefaultMediaTypeMappings());
- configureRequestedContentTypeResolver(builder);
+ configureContentTypeResolver(builder);
return builder.build();
}
@@ -186,7 +186,7 @@ public class WebReactiveConfigurationSupport implements ApplicationContextAware
/**
* Override to configure how the requested content type is resolved.
*/
- protected void configureRequestedContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
+ protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
}
/**
@@ -319,7 +319,9 @@ public class WebReactiveConfigurationSupport implements ApplicationContextAware
/**
* Adds default converters that sub-classes can call from
- * {@link #configureMessageReaders(List)}.
+ * {@link #configureMessageReaders(List)} for {@code byte[]},
+ * {@code ByteBuffer}, {@code String}, {@code Resource}, JAXB2, and Jackson
+ * (if present on the classpath).
*/
protected final void addDefaultHttpMessageReaders(List The given builder will create a composite of multiple
- * {@link RequestedContentTypeResolver}s, each defining a way to resolve the
- * the requested content type (accept HTTP header, path extension, parameter, etc).
- * @param builder factory that creates a {@link CompositeContentTypeResolver} instance
+ * {@link RequestedContentTypeResolver}s, each defining a way to resolve
+ * the the requested content type (accept HTTP header, path extension,
+ * parameter, etc).
+ * @param builder factory that creates a {@link CompositeContentTypeResolver}
*/
- default void configureRequestedContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
+ default void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
}
/**
@@ -79,71 +81,84 @@ public interface WebReactiveConfigurer {
}
/**
- * Provide custom argument resolvers without overriding the built-in ones.
- * @param resolvers a list of resolvers to add to the built-in ones
+ * Provide custom controller method argument resolvers. Such resolvers do
+ * not override and will be invoked after the built-in ones.
+ * @param resolvers a list of resolvers to add
*/
default void addArgumentResolvers(List If no message readers are specified, default readers will be added via
+ * Configure the message readers to use for decoding the request body where
+ * {@code @RequestBody} and {@code HttpEntity} controller method arguments
+ * are used. If none are specified, default ones are added based on
* {@link WebReactiveConfigurationSupport#addDefaultHttpMessageReaders}.
- * @param readers a list to add message readers to, initially an empty list
+ * See {@link #extendMessageReaders(List)} for adding readers
+ * in addition to the default ones.
+ * @param readers an empty list to add message readers to
*/
default void configureMessageReaders(List Only a single instance is allowed, an error will be thrown if multiple
- * {@code Validator}s are returned by {@code WebReactiveConfigurer}s.
- * The default implementation returns {@code Optional.empty()}.
+ * Provide a custom {@link Validator}.
+ * By default a validator for standard bean validation is created if
+ * bean validation api is present on the classpath.
*/
default Optional If no message writers are specified, default writers will be added via
+ * Configure the message writers to use to encode the response body based on
+ * the return values of {@code @ResponseBody}, and {@code ResponseEntity}
+ * controller methods. If none are specified, default ones are added based on
* {@link WebReactiveConfigurationSupport#addDefaultHttpMessageWriters(List)}.
- * @param writers a list to add message writers to, initially an empty list
+ * See {@link #extendMessageWriters(List)} for adding writers
+ * in addition to the default ones.
+ * @param writers a empty list to add message writers to
*/
default void configureMessageWriters(List In order to serve manifest files with the proper {@code "text/manifest"} content type,
* it is required to configure it with
* {@code requestedContentTypeResolverBuilder.mediaType("appcache", MediaType.valueOf("text/manifest")}
- * in {@code WebReactiveConfiguration.configureRequestedContentTypeResolver()}.
+ * in {@code WebReactiveConfiguration.configureContentTypeResolver()}.
*
* @author Rossen Stoyanchev
* @author Brian Clozel
diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfigurationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfigurationTests.java
index fcbc6c7f95e..6232937f594 100644
--- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfigurationTests.java
+++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfigurationTests.java
@@ -80,7 +80,7 @@ public class DelegatingWebReactiveConfigurationTests {
delegatingConfig.setConfigurers(Collections.singletonList(webReactiveConfigurer));
delegatingConfig.requestMappingHandlerMapping();
- verify(webReactiveConfigurer).configureRequestedContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
+ verify(webReactiveConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
verify(webReactiveConfigurer).addCorsMappings(any(CorsRegistry.class));
verify(webReactiveConfigurer).configurePathMatching(any(PathMatchConfigurer.class));
}
@@ -126,7 +126,7 @@ public class DelegatingWebReactiveConfigurationTests {
verify(webReactiveConfigurer).configureMessageWriters(writers.capture());
verify(webReactiveConfigurer).extendMessageWriters(writers.capture());
- verify(webReactiveConfigurer).configureRequestedContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
+ verify(webReactiveConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
}
@Test
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java
index 8de751cc153..3960aa06838 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java
@@ -31,8 +31,8 @@ import org.springframework.context.annotation.Import;
* If {@link WebMvcConfigurer} does not expose some advanced setting that
- * needs to be configured, consider removing the {@code @EnableWebMvc}
+ * Note: only one {@code @Configuration} class may have the
+ * {@code @EnableWebMvc} annotation to import the Spring Web MVC
+ * configuration. There can however be multiple {@code @Configuration} classes
+ * implementing {@code WebMvcConfigurer} in order to customize the provided
+ * configuration.
+ *
+ * If {@link WebMvcConfigurer} does not expose some more advanced setting that
+ * needs to be configured consider removing the {@code @EnableWebMvc}
* annotation and extending directly from {@link WebMvcConfigurationSupport}
* or {@link DelegatingWebMvcConfiguration}, e.g.:
*
* @Configuration
* @EnableWebMvc
- * @ComponentScan(basePackageClasses = { MyConfiguration.class })
- * public class MyWebConfiguration {
+ * @ComponentScan(basePackageClasses = MyConfiguration.class)
+ * public class MyConfiguration {
*
* }
*
@@ -44,7 +44,7 @@ import org.springframework.context.annotation.Import;
*
* @Configuration
* @EnableWebMvc
- * @ComponentScan(basePackageClasses = { MyConfiguration.class })
+ * @ComponentScan(basePackageClasses = MyConfiguration.class)
* public class MyConfiguration extends WebMvcConfigurerAdapter {
*
* @Override
@@ -57,12 +57,17 @@ import org.springframework.context.annotation.Import;
* converters.add(new MyHttpMessageConverter());
* }
*
- * // More overridden methods ...
* }
*
*
- *