Skip to content

Commit 6c098b3

Browse files
committed
Polish
1 parent b4b7c27 commit 6c098b3

File tree

8 files changed

+79
-51
lines changed

8 files changed

+79
-51
lines changed

spring-web-reactive/src/main/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public void setConfigurers(List<WebReactiveConfigurer> configurers) {
5151
}
5252

5353
@Override
54-
protected void configureRequestedContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
55-
this.configurers.configureRequestedContentTypeResolver(builder);
54+
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
55+
this.configurers.configureContentTypeResolver(builder);
5656
}
5757

5858
@Override

spring-web-reactive/src/main/java/org/springframework/web/reactive/config/EnableWebReactive.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@
3131
* <pre class="code">
3232
* &#064;Configuration
3333
* &#064;EnableWebReactive
34-
* &#064;ComponentScan(basePackageClasses = { MyConfiguration.class })
35-
* public class MyWebConfiguration {
34+
* &#064;ComponentScan(basePackageClasses = MyConfiguration.class)
35+
* public class MyConfiguration {
3636
*
3737
* }
3838
* </pre>
3939
*
40-
* <p>To customize the imported configuration, implement the interface
41-
* {@link WebReactiveConfigurer} and override individual methods, e.g.:
40+
* <p>To customize the imported configuration implement
41+
* {@link WebReactiveConfigurer} and override individual methods as shown below:
4242
*
4343
* <pre class="code">
4444
* &#064;Configuration
45-
* &#064;EnableWebMvc
46-
* &#064;ComponentScan(basePackageClasses = { MyConfiguration.class })
45+
* &#064;EnableWebReactive
46+
* &#064;ComponentScan(basePackageClasses = MyConfiguration.class)
4747
* public class MyConfiguration implements WebReactiveConfigurer {
4848
*
4949
* &#064;Override
@@ -56,17 +56,23 @@
5656
* messageWriters.add(new MyHttpMessageWriter());
5757
* }
5858
*
59-
* // More overridden methods ...
6059
* }
6160
* </pre>
6261
*
63-
* <p>If {@link WebReactiveConfigurer} does not expose some advanced setting that
64-
* needs to be configured, consider removing the {@code @EnableWebReactive}
62+
* <p><strong>Note:</strong> only one {@code @Configuration} class may have the
63+
* {@code @EnableWebReactive} annotation to import the Spring Web Reactive
64+
* configuration. There can however be multiple {@code @Configuration} classes
65+
* implementing {@code WebReactiveConfigurer} in order to customize the provided
66+
* configuration.
67+
*
68+
* <p>If {@link WebReactiveConfigurer} does not expose some more advanced setting
69+
* that needs to be configured consider removing the {@code @EnableWebReactive}
6570
* annotation and extending directly from {@link WebReactiveConfigurationSupport}
6671
* or {@link DelegatingWebReactiveConfiguration} if you still want to allow
6772
* {@link WebReactiveConfigurer} instances to customize the configuration.
6873
*
6974
* @author Brian Clozel
75+
* @author Rossen Stoyanchev
7076
* @since 5.0
7177
* @see WebReactiveConfigurer
7278
* @see WebReactiveConfigurationSupport

spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfigurationSupport.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
167167
public CompositeContentTypeResolver webReactiveContentTypeResolver() {
168168
RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder();
169169
builder.mediaTypes(getDefaultMediaTypeMappings());
170-
configureRequestedContentTypeResolver(builder);
170+
configureContentTypeResolver(builder);
171171
return builder.build();
172172
}
173173

@@ -186,7 +186,7 @@ protected Map<String, MediaType> getDefaultMediaTypeMappings() {
186186
/**
187187
* Override to configure how the requested content type is resolved.
188188
*/
189-
protected void configureRequestedContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
189+
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
190190
}
191191

192192
/**
@@ -319,7 +319,9 @@ protected void configureMessageReaders(List<HttpMessageReader<?>> messageReaders
319319

320320
/**
321321
* Adds default converters that sub-classes can call from
322-
* {@link #configureMessageReaders(List)}.
322+
* {@link #configureMessageReaders(List)} for {@code byte[]},
323+
* {@code ByteBuffer}, {@code String}, {@code Resource}, JAXB2, and Jackson
324+
* (if present on the classpath).
323325
*/
324326
protected final void addDefaultHttpMessageReaders(List<HttpMessageReader<?>> readers) {
325327
readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));

spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfigurer.java

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,20 @@
4141
* overriding the relevant methods for your needs.
4242
*
4343
* @author Brian Clozel
44+
* @author Rossen Stoyanchev
4445
* @since 5.0
4546
*/
4647
public interface WebReactiveConfigurer {
4748

4849
/**
49-
* Configure how the requested content type is resolved.
50+
* Configure how the content type requested for the response is resolved.
5051
* <p>The given builder will create a composite of multiple
51-
* {@link RequestedContentTypeResolver}s, each defining a way to resolve the
52-
* the requested content type (accept HTTP header, path extension, parameter, etc).
53-
* @param builder factory that creates a {@link CompositeContentTypeResolver} instance
52+
* {@link RequestedContentTypeResolver}s, each defining a way to resolve
53+
* the the requested content type (accept HTTP header, path extension,
54+
* parameter, etc).
55+
* @param builder factory that creates a {@link CompositeContentTypeResolver}
5456
*/
55-
default void configureRequestedContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
57+
default void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
5658
}
5759

5860
/**
@@ -79,71 +81,84 @@ default void addResourceHandlers(ResourceHandlerRegistry registry) {
7981
}
8082

8183
/**
82-
* Provide custom argument resolvers without overriding the built-in ones.
83-
* @param resolvers a list of resolvers to add to the built-in ones
84+
* Provide custom controller method argument resolvers. Such resolvers do
85+
* not override and will be invoked after the built-in ones.
86+
* @param resolvers a list of resolvers to add
8487
*/
8588
default void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
8689
}
8790

8891
/**
89-
* Configure the message readers to use for decoding controller method arguments.
90-
* <p>If no message readers are specified, default readers will be added via
92+
* Configure the message readers to use for decoding the request body where
93+
* {@code @RequestBody} and {@code HttpEntity} controller method arguments
94+
* are used. If none are specified, default ones are added based on
9195
* {@link WebReactiveConfigurationSupport#addDefaultHttpMessageReaders}.
92-
* @param readers a list to add message readers to, initially an empty list
96+
* <p>See {@link #extendMessageReaders(List)} for adding readers
97+
* in addition to the default ones.
98+
* @param readers an empty list to add message readers to
9399
*/
94100
default void configureMessageReaders(List<HttpMessageReader<?>> readers) {
95101
}
96102

97103
/**
98-
* Modify the list of message readers to use for decoding controller method arguments,
99-
* for example to add some in addition to the ones already configured.
104+
* An alternative to {@link #configureMessageReaders(List)} that allows
105+
* modifying the message readers to use after default ones have been added.
100106
*/
101107
default void extendMessageReaders(List<HttpMessageReader<?>> readers) {
102108
}
103109

104110
/**
105-
* Add custom {@link Converter}s and {@link Formatter}s.
111+
* Add custom {@link Converter}s and {@link Formatter}s for performing type
112+
* conversion and formatting of controller method arguments.
106113
*/
107114
default void addFormatters(FormatterRegistry registry) {
108115
}
109116

110117
/**
111-
* Provide a custom {@link Validator}, instead of the instance configured by default.
112-
* <p>Only a single instance is allowed, an error will be thrown if multiple
113-
* {@code Validator}s are returned by {@code WebReactiveConfigurer}s.
114-
* The default implementation returns {@code Optional.empty()}.
118+
* Provide a custom {@link Validator}.
119+
* <p>By default a validator for standard bean validation is created if
120+
* bean validation api is present on the classpath.
115121
*/
116122
default Optional<Validator> getValidator() {
117123
return Optional.empty();
118124
}
119125

120126
/**
121-
* Provide a custom {@link MessageCodesResolver}, instead of using the one
122-
* provided by {@link org.springframework.validation.DataBinder} instances.
123-
* The default implementation returns {@code Optional.empty()}.
127+
* Provide a custom {@link MessageCodesResolver} to use for data binding
128+
* instead of the one created by default in
129+
* {@link org.springframework.validation.DataBinder}.
124130
*/
125131
default Optional<MessageCodesResolver> getMessageCodesResolver() {
126132
return Optional.empty();
127133
}
128134

129135
/**
130-
* Configure the message writers to use for encoding return values.
131-
* <p>If no message writers are specified, default writers will be added via
136+
* Configure the message writers to use to encode the response body based on
137+
* the return values of {@code @ResponseBody}, and {@code ResponseEntity}
138+
* controller methods. If none are specified, default ones are added based on
132139
* {@link WebReactiveConfigurationSupport#addDefaultHttpMessageWriters(List)}.
133-
* @param writers a list to add message writers to, initially an empty list
140+
* <p>See {@link #extendMessageWriters(List)} for adding writers
141+
* in addition to the default ones.
142+
* @param writers a empty list to add message writers to
134143
*/
135144
default void configureMessageWriters(List<HttpMessageWriter<?>> writers) {
136145
}
137146

138147
/**
139-
* Modify the list of message writers to use for encoding return values,
140-
* for example to add some in addition to the ones already configured.
148+
* An alternative to {@link #configureMessageWriters(List)} that allows
149+
* modifying the message writers to use after default ones have been added.
141150
*/
142151
default void extendMessageWriters(List<HttpMessageWriter<?>> writers) {
143152
}
144153

145154
/**
146-
* Configure view resolution for supporting template engines.
155+
* Configure view resolution for processing the return values of controller
156+
* methods that rely on resolving a
157+
* {@link org.springframework.web.reactive.result.view.View} to render
158+
* the response with. By default all controller methods rely on view
159+
* resolution unless annotated with {@code @ResponseBody} or explicitly
160+
* return {@code ResponseEntity}. A view may be specified explicitly with
161+
* a String return value or implicitly, e.g. {@code void} return value.
147162
* @see ViewResolverRegistry
148163
*/
149164
default void configureViewResolvers(ViewResolverRegistry registry) {

spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfigurerComposite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public void addWebReactiveConfigurers(List<WebReactiveConfigurer> configurers) {
5151

5252

5353
@Override
54-
public void configureRequestedContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
55-
this.delegates.stream().forEach(delegate -> delegate.configureRequestedContentTypeResolver(builder));
54+
public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
55+
this.delegates.stream().forEach(delegate -> delegate.configureContentTypeResolver(builder));
5656
}
5757

5858
@Override

spring-web-reactive/src/main/java/org/springframework/web/reactive/resource/AppCacheManifestTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
* <p>In order to serve manifest files with the proper {@code "text/manifest"} content type,
6262
* it is required to configure it with
6363
* {@code requestedContentTypeResolverBuilder.mediaType("appcache", MediaType.valueOf("text/manifest")}
64-
* in {@code WebReactiveConfiguration.configureRequestedContentTypeResolver()}.
64+
* in {@code WebReactiveConfiguration.configureContentTypeResolver()}.
6565
*
6666
* @author Rossen Stoyanchev
6767
* @author Brian Clozel

spring-web-reactive/src/test/java/org/springframework/web/reactive/config/DelegatingWebReactiveConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void requestMappingHandlerMapping() throws Exception {
8080
delegatingConfig.setConfigurers(Collections.singletonList(webReactiveConfigurer));
8181
delegatingConfig.requestMappingHandlerMapping();
8282

83-
verify(webReactiveConfigurer).configureRequestedContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
83+
verify(webReactiveConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
8484
verify(webReactiveConfigurer).addCorsMappings(any(CorsRegistry.class));
8585
verify(webReactiveConfigurer).configurePathMatching(any(PathMatchConfigurer.class));
8686
}
@@ -126,7 +126,7 @@ public void responseBodyResultHandler() throws Exception {
126126

127127
verify(webReactiveConfigurer).configureMessageWriters(writers.capture());
128128
verify(webReactiveConfigurer).extendMessageWriters(writers.capture());
129-
verify(webReactiveConfigurer).configureRequestedContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
129+
verify(webReactiveConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
130130
}
131131

132132
@Test

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
* <pre class="code">
3232
* &#064;Configuration
3333
* &#064;EnableWebMvc
34-
* &#064;ComponentScan(basePackageClasses = { MyConfiguration.class })
35-
* public class MyWebConfiguration {
34+
* &#064;ComponentScan(basePackageClasses = MyConfiguration.class)
35+
* public class MyConfiguration {
3636
*
3737
* }
3838
* </pre>
@@ -44,7 +44,7 @@
4444
* <pre class="code">
4545
* &#064;Configuration
4646
* &#064;EnableWebMvc
47-
* &#064;ComponentScan(basePackageClasses = { MyConfiguration.class })
47+
* &#064;ComponentScan(basePackageClasses = MyConfiguration.class)
4848
* public class MyConfiguration extends WebMvcConfigurerAdapter {
4949
*
5050
* &#064;Override
@@ -57,12 +57,17 @@
5757
* converters.add(new MyHttpMessageConverter());
5858
* }
5959
*
60-
* // More overridden methods ...
6160
* }
6261
* </pre>
6362
*
64-
* <p>If {@link WebMvcConfigurer} does not expose some advanced setting that
65-
* needs to be configured, consider removing the {@code @EnableWebMvc}
63+
* <p><strong>Note:</strong> only one {@code @Configuration} class may have the
64+
* {@code @EnableWebMvc} annotation to import the Spring Web MVC
65+
* configuration. There can however be multiple {@code @Configuration} classes
66+
* implementing {@code WebMvcConfigurer} in order to customize the provided
67+
* configuration.
68+
*
69+
* <p>If {@link WebMvcConfigurer} does not expose some more advanced setting that
70+
* needs to be configured consider removing the {@code @EnableWebMvc}
6671
* annotation and extending directly from {@link WebMvcConfigurationSupport}
6772
* or {@link DelegatingWebMvcConfiguration}, e.g.:
6873
*

0 commit comments

Comments
 (0)