Polish
This commit is contained in:
@@ -51,8 +51,8 @@ public class DelegatingWebReactiveConfiguration extends WebReactiveConfiguration
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureRequestedContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
|
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
|
||||||
this.configurers.configureRequestedContentTypeResolver(builder);
|
this.configurers.configureContentTypeResolver(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -31,19 +31,19 @@ import org.springframework.context.annotation.Import;
|
|||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* @Configuration
|
* @Configuration
|
||||||
* @EnableWebReactive
|
* @EnableWebReactive
|
||||||
* @ComponentScan(basePackageClasses = { MyConfiguration.class })
|
* @ComponentScan(basePackageClasses = MyConfiguration.class)
|
||||||
* public class MyWebConfiguration {
|
* public class MyConfiguration {
|
||||||
*
|
*
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <p>To customize the imported configuration, implement the interface
|
* <p>To customize the imported configuration implement
|
||||||
* {@link WebReactiveConfigurer} and override individual methods, e.g.:
|
* {@link WebReactiveConfigurer} and override individual methods as shown below:
|
||||||
*
|
*
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* @Configuration
|
* @Configuration
|
||||||
* @EnableWebMvc
|
* @EnableWebReactive
|
||||||
* @ComponentScan(basePackageClasses = { MyConfiguration.class })
|
* @ComponentScan(basePackageClasses = MyConfiguration.class)
|
||||||
* public class MyConfiguration implements WebReactiveConfigurer {
|
* public class MyConfiguration implements WebReactiveConfigurer {
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
@@ -56,17 +56,23 @@ import org.springframework.context.annotation.Import;
|
|||||||
* messageWriters.add(new MyHttpMessageWriter());
|
* messageWriters.add(new MyHttpMessageWriter());
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // More overridden methods ...
|
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <p>If {@link WebReactiveConfigurer} does not expose some advanced setting that
|
* <p><strong>Note:</strong> only one {@code @Configuration} class may have the
|
||||||
* needs to be configured, consider removing the {@code @EnableWebReactive}
|
* {@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.
|
||||||
|
*
|
||||||
|
* <p>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}
|
* annotation and extending directly from {@link WebReactiveConfigurationSupport}
|
||||||
* or {@link DelegatingWebReactiveConfiguration} if you still want to allow
|
* or {@link DelegatingWebReactiveConfiguration} if you still want to allow
|
||||||
* {@link WebReactiveConfigurer} instances to customize the configuration.
|
* {@link WebReactiveConfigurer} instances to customize the configuration.
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
* @see WebReactiveConfigurer
|
* @see WebReactiveConfigurer
|
||||||
* @see WebReactiveConfigurationSupport
|
* @see WebReactiveConfigurationSupport
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ public class WebReactiveConfigurationSupport implements ApplicationContextAware
|
|||||||
public CompositeContentTypeResolver webReactiveContentTypeResolver() {
|
public CompositeContentTypeResolver webReactiveContentTypeResolver() {
|
||||||
RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder();
|
RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder();
|
||||||
builder.mediaTypes(getDefaultMediaTypeMappings());
|
builder.mediaTypes(getDefaultMediaTypeMappings());
|
||||||
configureRequestedContentTypeResolver(builder);
|
configureContentTypeResolver(builder);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ public class WebReactiveConfigurationSupport implements ApplicationContextAware
|
|||||||
/**
|
/**
|
||||||
* Override to configure how the requested content type is resolved.
|
* 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
|
* 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<HttpMessageReader<?>> readers) {
|
protected final void addDefaultHttpMessageReaders(List<HttpMessageReader<?>> readers) {
|
||||||
readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
|
readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
|
||||||
|
|||||||
@@ -41,18 +41,20 @@ import org.springframework.web.reactive.result.method.HandlerMethodArgumentResol
|
|||||||
* overriding the relevant methods for your needs.
|
* overriding the relevant methods for your needs.
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public interface WebReactiveConfigurer {
|
public interface WebReactiveConfigurer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure how the requested content type is resolved.
|
* Configure how the content type requested for the response is resolved.
|
||||||
* <p>The given builder will create a composite of multiple
|
* <p>The given builder will create a composite of multiple
|
||||||
* {@link RequestedContentTypeResolver}s, each defining a way to resolve the
|
* {@link RequestedContentTypeResolver}s, each defining a way to resolve
|
||||||
* the requested content type (accept HTTP header, path extension, parameter, etc).
|
* the the requested content type (accept HTTP header, path extension,
|
||||||
* @param builder factory that creates a {@link CompositeContentTypeResolver} instance
|
* 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.
|
* Provide custom controller method argument resolvers. Such resolvers do
|
||||||
* @param resolvers a list of resolvers to add to the built-in ones
|
* not override and will be invoked after the built-in ones.
|
||||||
|
* @param resolvers a list of resolvers to add
|
||||||
*/
|
*/
|
||||||
default void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
|
default void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the message readers to use for decoding controller method arguments.
|
* Configure the message readers to use for decoding the request body where
|
||||||
* <p>If no message readers are specified, default readers will be added via
|
* {@code @RequestBody} and {@code HttpEntity} controller method arguments
|
||||||
|
* are used. If none are specified, default ones are added based on
|
||||||
* {@link WebReactiveConfigurationSupport#addDefaultHttpMessageReaders}.
|
* {@link WebReactiveConfigurationSupport#addDefaultHttpMessageReaders}.
|
||||||
* @param readers a list to add message readers to, initially an empty list
|
* <p>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<HttpMessageReader<?>> readers) {
|
default void configureMessageReaders(List<HttpMessageReader<?>> readers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify the list of message readers to use for decoding controller method arguments,
|
* An alternative to {@link #configureMessageReaders(List)} that allows
|
||||||
* for example to add some in addition to the ones already configured.
|
* modifying the message readers to use after default ones have been added.
|
||||||
*/
|
*/
|
||||||
default void extendMessageReaders(List<HttpMessageReader<?>> readers) {
|
default void extendMessageReaders(List<HttpMessageReader<?>> readers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add custom {@link Converter}s and {@link Formatter}s.
|
* Add custom {@link Converter}s and {@link Formatter}s for performing type
|
||||||
|
* conversion and formatting of controller method arguments.
|
||||||
*/
|
*/
|
||||||
default void addFormatters(FormatterRegistry registry) {
|
default void addFormatters(FormatterRegistry registry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a custom {@link Validator}, instead of the instance configured by default.
|
* Provide a custom {@link Validator}.
|
||||||
* <p>Only a single instance is allowed, an error will be thrown if multiple
|
* <p>By default a validator for standard bean validation is created if
|
||||||
* {@code Validator}s are returned by {@code WebReactiveConfigurer}s.
|
* bean validation api is present on the classpath.
|
||||||
* The default implementation returns {@code Optional.empty()}.
|
|
||||||
*/
|
*/
|
||||||
default Optional<Validator> getValidator() {
|
default Optional<Validator> getValidator() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a custom {@link MessageCodesResolver}, instead of using the one
|
* Provide a custom {@link MessageCodesResolver} to use for data binding
|
||||||
* provided by {@link org.springframework.validation.DataBinder} instances.
|
* instead of the one created by default in
|
||||||
* The default implementation returns {@code Optional.empty()}.
|
* {@link org.springframework.validation.DataBinder}.
|
||||||
*/
|
*/
|
||||||
default Optional<MessageCodesResolver> getMessageCodesResolver() {
|
default Optional<MessageCodesResolver> getMessageCodesResolver() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the message writers to use for encoding return values.
|
* Configure the message writers to use to encode the response body based on
|
||||||
* <p>If no message writers are specified, default writers will be added via
|
* 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)}.
|
* {@link WebReactiveConfigurationSupport#addDefaultHttpMessageWriters(List)}.
|
||||||
* @param writers a list to add message writers to, initially an empty list
|
* <p>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<HttpMessageWriter<?>> writers) {
|
default void configureMessageWriters(List<HttpMessageWriter<?>> writers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify the list of message writers to use for encoding return values,
|
* An alternative to {@link #configureMessageWriters(List)} that allows
|
||||||
* for example to add some in addition to the ones already configured.
|
* modifying the message writers to use after default ones have been added.
|
||||||
*/
|
*/
|
||||||
default void extendMessageWriters(List<HttpMessageWriter<?>> writers) {
|
default void extendMessageWriters(List<HttpMessageWriter<?>> writers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure view resolution for supporting template engines.
|
* Configure view resolution for processing the return values of controller
|
||||||
|
* methods that rely on resolving a
|
||||||
|
* {@link org.springframework.web.reactive.result.view.View} to render
|
||||||
|
* the response with. By default all controller methods rely on view
|
||||||
|
* resolution unless annotated with {@code @ResponseBody} or explicitly
|
||||||
|
* return {@code ResponseEntity}. A view may be specified explicitly with
|
||||||
|
* a String return value or implicitly, e.g. {@code void} return value.
|
||||||
* @see ViewResolverRegistry
|
* @see ViewResolverRegistry
|
||||||
*/
|
*/
|
||||||
default void configureViewResolvers(ViewResolverRegistry registry) {
|
default void configureViewResolvers(ViewResolverRegistry registry) {
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public class WebReactiveConfigurerComposite implements WebReactiveConfigurer {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureRequestedContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
|
public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
|
||||||
this.delegates.stream().forEach(delegate -> delegate.configureRequestedContentTypeResolver(builder));
|
this.delegates.stream().forEach(delegate -> delegate.configureContentTypeResolver(builder));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ import org.springframework.web.server.ServerWebExchange;
|
|||||||
* <p>In order to serve manifest files with the proper {@code "text/manifest"} content type,
|
* <p>In order to serve manifest files with the proper {@code "text/manifest"} content type,
|
||||||
* it is required to configure it with
|
* it is required to configure it with
|
||||||
* {@code requestedContentTypeResolverBuilder.mediaType("appcache", MediaType.valueOf("text/manifest")}
|
* {@code requestedContentTypeResolverBuilder.mediaType("appcache", MediaType.valueOf("text/manifest")}
|
||||||
* in {@code WebReactiveConfiguration.configureRequestedContentTypeResolver()}.
|
* in {@code WebReactiveConfiguration.configureContentTypeResolver()}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class DelegatingWebReactiveConfigurationTests {
|
|||||||
delegatingConfig.setConfigurers(Collections.singletonList(webReactiveConfigurer));
|
delegatingConfig.setConfigurers(Collections.singletonList(webReactiveConfigurer));
|
||||||
delegatingConfig.requestMappingHandlerMapping();
|
delegatingConfig.requestMappingHandlerMapping();
|
||||||
|
|
||||||
verify(webReactiveConfigurer).configureRequestedContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
|
verify(webReactiveConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
|
||||||
verify(webReactiveConfigurer).addCorsMappings(any(CorsRegistry.class));
|
verify(webReactiveConfigurer).addCorsMappings(any(CorsRegistry.class));
|
||||||
verify(webReactiveConfigurer).configurePathMatching(any(PathMatchConfigurer.class));
|
verify(webReactiveConfigurer).configurePathMatching(any(PathMatchConfigurer.class));
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ public class DelegatingWebReactiveConfigurationTests {
|
|||||||
|
|
||||||
verify(webReactiveConfigurer).configureMessageWriters(writers.capture());
|
verify(webReactiveConfigurer).configureMessageWriters(writers.capture());
|
||||||
verify(webReactiveConfigurer).extendMessageWriters(writers.capture());
|
verify(webReactiveConfigurer).extendMessageWriters(writers.capture());
|
||||||
verify(webReactiveConfigurer).configureRequestedContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
|
verify(webReactiveConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ import org.springframework.context.annotation.Import;
|
|||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* @Configuration
|
* @Configuration
|
||||||
* @EnableWebMvc
|
* @EnableWebMvc
|
||||||
* @ComponentScan(basePackageClasses = { MyConfiguration.class })
|
* @ComponentScan(basePackageClasses = MyConfiguration.class)
|
||||||
* public class MyWebConfiguration {
|
* public class MyConfiguration {
|
||||||
*
|
*
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
@@ -44,7 +44,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* @Configuration
|
* @Configuration
|
||||||
* @EnableWebMvc
|
* @EnableWebMvc
|
||||||
* @ComponentScan(basePackageClasses = { MyConfiguration.class })
|
* @ComponentScan(basePackageClasses = MyConfiguration.class)
|
||||||
* public class MyConfiguration extends WebMvcConfigurerAdapter {
|
* public class MyConfiguration extends WebMvcConfigurerAdapter {
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
@@ -57,12 +57,17 @@ import org.springframework.context.annotation.Import;
|
|||||||
* converters.add(new MyHttpMessageConverter());
|
* converters.add(new MyHttpMessageConverter());
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // More overridden methods ...
|
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <p>If {@link WebMvcConfigurer} does not expose some advanced setting that
|
* <p><strong>Note:</strong> only one {@code @Configuration} class may have the
|
||||||
* needs to be configured, consider removing the {@code @EnableWebMvc}
|
* {@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.
|
||||||
|
*
|
||||||
|
* <p>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}
|
* annotation and extending directly from {@link WebMvcConfigurationSupport}
|
||||||
* or {@link DelegatingWebMvcConfiguration}, e.g.:
|
* or {@link DelegatingWebMvcConfiguration}, e.g.:
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user