Skip to content

Commit 21b7dc1

Browse files
committed
Backport of WebMvcConfigurationSupport javadoc revision
Includes related polishing.
1 parent a403a75 commit 21b7dc1

File tree

3 files changed

+87
-92
lines changed

3 files changed

+87
-92
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/ResultMatcher.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,6 @@ public interface ResultMatcher {
5050

5151
/**
5252
* Assert the result of an executed request.
53-
*
5453
* @param result the result of the executed request
5554
* @throws Exception if a failure occurs
5655
*/

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

Lines changed: 76 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
* subclass and {@link Bean @Bean} to overridden {@link Bean @Bean} methods.
106106
* For more details see the javadoc of {@link EnableWebMvc @EnableWebMvc}.
107107
*
108-
* <p>This class registers the following {@link HandlerMapping}s:</p>
108+
* <p>This class registers the following {@link HandlerMapping HandlerMappings}:</p>
109109
* <ul>
110110
* <li>{@link RequestMappingHandlerMapping}
111111
* ordered at 0 for mapping requests to annotated controller methods.
@@ -119,14 +119,14 @@
119119
* ordered at {@code Integer.MAX_VALUE} to forward requests to the default servlet.
120120
* </ul>
121121
*
122-
* <p>Registers these {@link HandlerAdapter}s:
122+
* <p>Registers these {@link HandlerAdapter HandlerAdapters}:
123123
* <ul>
124124
* <li>{@link RequestMappingHandlerAdapter}
125125
* for processing requests with annotated controller methods.
126126
* <li>{@link HttpRequestHandlerAdapter}
127-
* for processing requests with {@link HttpRequestHandler}s.
127+
* for processing requests with {@link HttpRequestHandler HttpRequestHandlers}.
128128
* <li>{@link SimpleControllerHandlerAdapter}
129-
* for processing requests with interface-based {@link Controller}s.
129+
* for processing requests with interface-based {@link Controller Controllers}.
130130
* </ul>
131131
*
132132
* <p>Registers a {@link HandlerExceptionResolverComposite} with this chain of
@@ -157,7 +157,7 @@
157157
* <li>a {@link DefaultFormattingConversionService}
158158
* <li>a {@link org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean}
159159
* if a JSR-303 implementation is available on the classpath
160-
* <li>a range of {@link HttpMessageConverter}s depending on the third-party
160+
* <li>a range of {@link HttpMessageConverter HttpMessageConverters} depending on the third-party
161161
* libraries available on the classpath.
162162
* </ul>
163163
*
@@ -171,7 +171,7 @@
171171
*/
172172
public class WebMvcConfigurationSupport implements ApplicationContextAware, ServletContextAware {
173173

174-
private static boolean romePresent =
174+
private static final boolean romePresent =
175175
ClassUtils.isPresent("com.rometools.rome.feed.WireFeed",
176176
WebMvcConfigurationSupport.class.getClassLoader());
177177

@@ -260,15 +260,20 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
260260
mapping.setCorsConfigurations(getCorsConfigurations());
261261

262262
PathMatchConfigurer configurer = getPathMatchConfigurer();
263-
if (configurer.isUseSuffixPatternMatch() != null) {
264-
mapping.setUseSuffixPatternMatch(configurer.isUseSuffixPatternMatch());
263+
264+
Boolean useSuffixPatternMatch = configurer.isUseSuffixPatternMatch();
265+
if (useSuffixPatternMatch != null) {
266+
mapping.setUseSuffixPatternMatch(useSuffixPatternMatch);
265267
}
266-
if (configurer.isUseRegisteredSuffixPatternMatch() != null) {
267-
mapping.setUseRegisteredSuffixPatternMatch(configurer.isUseRegisteredSuffixPatternMatch());
268+
Boolean useRegisteredSuffixPatternMatch = configurer.isUseRegisteredSuffixPatternMatch();
269+
if (useRegisteredSuffixPatternMatch != null) {
270+
mapping.setUseRegisteredSuffixPatternMatch(useRegisteredSuffixPatternMatch);
268271
}
269-
if (configurer.isUseTrailingSlashMatch() != null) {
270-
mapping.setUseTrailingSlashMatch(configurer.isUseTrailingSlashMatch());
272+
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
273+
if (useTrailingSlashMatch != null) {
274+
mapping.setUseTrailingSlashMatch(useTrailingSlashMatch);
271275
}
276+
272277
UrlPathHelper pathHelper = configurer.getUrlPathHelper();
273278
if (pathHelper != null) {
274279
mapping.setUrlPathHelper(pathHelper);
@@ -292,8 +297,8 @@ protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
292297

293298
/**
294299
* Provide access to the shared handler interceptors used to configure
295-
* {@link HandlerMapping} instances with. This method cannot be overridden,
296-
* use {@link #addInterceptors(InterceptorRegistry)} instead.
300+
* {@link HandlerMapping} instances with.
301+
* <p>This method cannot be overridden; use {@link #addInterceptors} instead.
297302
*/
298303
protected final Object[] getInterceptors() {
299304
if (this.interceptors == null) {
@@ -329,15 +334,15 @@ protected PathMatchConfigurer getPathMatchConfigurer() {
329334

330335
/**
331336
* Override this method to configure path matching options.
332-
* @see PathMatchConfigurer
333337
* @since 4.0.3
338+
* @see PathMatchConfigurer
334339
*/
335340
protected void configurePathMatch(PathMatchConfigurer configurer) {
336341
}
337342

338343
/**
339344
* Return a global {@link PathMatcher} instance for path matching
340-
* patterns in {@link HandlerMapping}s.
345+
* patterns in {@link HandlerMapping HandlerMappings}.
341346
* This instance can be configured using the {@link PathMatchConfigurer}
342347
* in {@link #configurePathMatch(PathMatchConfigurer)}.
343348
* @since 4.1
@@ -350,7 +355,7 @@ public PathMatcher mvcPathMatcher() {
350355

351356
/**
352357
* Return a global {@link UrlPathHelper} instance for path matching
353-
* patterns in {@link HandlerMapping}s.
358+
* patterns in {@link HandlerMapping HandlerMappings}.
354359
* This instance can be configured using the {@link PathMatchConfigurer}
355360
* in {@link #configurePathMatch(PathMatchConfigurer)}.
356361
* @since 4.1
@@ -586,9 +591,8 @@ protected void configureAsyncSupport(AsyncSupportConfigurer configurer) {
586591
}
587592

588593
/**
589-
* Return a {@link FormattingConversionService} for use with annotated
590-
* controller methods and the {@code spring:eval} JSP tag.
591-
* Also see {@link #addFormatters} as an alternative to overriding this method.
594+
* Return a {@link FormattingConversionService} for use with annotated controllers.
595+
* <p>See {@link #addFormatters} as an alternative to overriding this method.
592596
*/
593597
@Bean
594598
public FormattingConversionService mvcConversionService() {
@@ -598,7 +602,9 @@ public FormattingConversionService mvcConversionService() {
598602
}
599603

600604
/**
601-
* Override this method to add custom {@link Converter}s and {@link Formatter}s.
605+
* Override this method to add custom {@link Converter} and/or {@link Formatter}
606+
* delegates to the common {@link FormattingConversionService}.
607+
* @see #mvcConversionService()
602608
*/
603609
protected void addFormatters(FormatterRegistry registry) {
604610
}
@@ -645,9 +651,8 @@ protected Validator getValidator() {
645651

646652
/**
647653
* Provide access to the shared custom argument resolvers used by the
648-
* {@link RequestMappingHandlerAdapter} and the
649-
* {@link ExceptionHandlerExceptionResolver}. This method cannot be
650-
* overridden, use {@link #addArgumentResolvers(List)} instead.
654+
* {@link RequestMappingHandlerAdapter} and the {@link ExceptionHandlerExceptionResolver}.
655+
* <p>This method cannot be overridden; use {@link #addArgumentResolvers} instead.
651656
* @since 4.3
652657
*/
653658
protected final List<HandlerMethodArgumentResolver> getArgumentResolvers() {
@@ -659,24 +664,21 @@ protected final List<HandlerMethodArgumentResolver> getArgumentResolvers() {
659664
}
660665

661666
/**
662-
* Add custom {@link HandlerMethodArgumentResolver}s to use in addition to
663-
* the ones registered by default.
664-
* <p>Custom argument resolvers are invoked before built-in resolvers
665-
* except for those that rely on the presence of annotations (e.g.
666-
* {@code @RequestParameter}, {@code @PathVariable}, etc.).
667-
* The latter can be customized by configuring the
667+
* Add custom {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}
668+
* to use in addition to the ones registered by default.
669+
* <p>Custom argument resolvers are invoked before built-in resolvers except for
670+
* those that rely on the presence of annotations (e.g. {@code @RequestParameter},
671+
* {@code @PathVariable}, etc). The latter can be customized by configuring the
668672
* {@link RequestMappingHandlerAdapter} directly.
669-
* @param argumentResolvers the list of custom converters;
670-
* initially an empty list.
673+
* @param argumentResolvers the list of custom converters (initially an empty list)
671674
*/
672675
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
673676
}
674677

675678
/**
676679
* Provide access to the shared return value handlers used by the
677-
* {@link RequestMappingHandlerAdapter} and the
678-
* {@link ExceptionHandlerExceptionResolver}. This method cannot be
679-
* overridden, use {@link #addReturnValueHandlers(List)} instead.
680+
* {@link RequestMappingHandlerAdapter} and the {@link ExceptionHandlerExceptionResolver}.
681+
* <p>This method cannot be overridden; use {@link #addReturnValueHandlers} instead.
680682
* @since 4.3
681683
*/
682684
protected final List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
@@ -688,27 +690,23 @@ protected final List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
688690
}
689691

690692
/**
691-
* Add custom {@link HandlerMethodReturnValueHandler}s in addition to the
692-
* ones registered by default.
693-
* <p>Custom return value handlers are invoked before built-in ones except
694-
* for those that rely on the presence of annotations (e.g.
695-
* {@code @ResponseBody}, {@code @ModelAttribute}, etc.).
696-
* The latter can be customized by configuring the
693+
* Add custom {@link HandlerMethodReturnValueHandler HandlerMethodReturnValueHandlers}
694+
* in addition to the ones registered by default.
695+
* <p>Custom return value handlers are invoked before built-in ones except for
696+
* those that rely on the presence of annotations (e.g. {@code @ResponseBody},
697+
* {@code @ModelAttribute}, etc). The latter can be customized by configuring the
697698
* {@link RequestMappingHandlerAdapter} directly.
698-
* @param returnValueHandlers the list of custom handlers;
699-
* initially an empty list.
699+
* @param returnValueHandlers the list of custom handlers (initially an empty list)
700700
*/
701701
protected void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
702702
}
703703

704704
/**
705-
* Provides access to the shared {@link HttpMessageConverter}s used by the
706-
* {@link RequestMappingHandlerAdapter} and the
705+
* Provides access to the shared {@link HttpMessageConverter HttpMessageConverters}
706+
* used by the {@link RequestMappingHandlerAdapter} and the
707707
* {@link ExceptionHandlerExceptionResolver}.
708-
* This method cannot be overridden.
709-
* Use {@link #configureMessageConverters(List)} instead.
710-
* Also see {@link #addDefaultHttpMessageConverters(List)} that can be
711-
* used to add default message converters.
708+
* <p>This method cannot be overridden; use {@link #configureMessageConverters} instead.
709+
* Also see {@link #addDefaultHttpMessageConverters} for adding default message converters.
712710
*/
713711
protected final List<HttpMessageConverter<?>> getMessageConverters() {
714712
if (this.messageConverters == null) {
@@ -723,32 +721,30 @@ protected final List<HttpMessageConverter<?>> getMessageConverters() {
723721
}
724722

725723
/**
726-
* Override this method to add custom {@link HttpMessageConverter}s to use
727-
* with the {@link RequestMappingHandlerAdapter} and the
728-
* {@link ExceptionHandlerExceptionResolver}. Adding converters to the
729-
* list turns off the default converters that would otherwise be registered
730-
* by default. Also see {@link #addDefaultHttpMessageConverters(List)} that
731-
* can be used to add default message converters.
732-
* @param converters a list to add message converters to;
733-
* initially an empty list.
724+
* Override this method to add custom {@link HttpMessageConverter HttpMessageConverters}
725+
* to use with the {@link RequestMappingHandlerAdapter} and the
726+
* {@link ExceptionHandlerExceptionResolver}.
727+
* <p>Adding converters to the list turns off the default converters that would
728+
* otherwise be registered by default. Also see {@link #addDefaultHttpMessageConverters}
729+
* for adding default message converters.
730+
* @param converters a list to add message converters to (initially an empty list)
734731
*/
735732
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
736733
}
737734

738735
/**
739-
* Override this method to extend or modify the list of converters after it
740-
* has been configured. This may be useful for example to allow default
741-
* converters to be registered and then insert a custom converter through
742-
* this method.
743-
* @param converters the list of configured converters to extend.
736+
* Override this method to extend or modify the list of converters after it has
737+
* been configured. This may be useful for example to allow default converters
738+
* to be registered and then insert a custom converter through this method.
739+
* @param converters the list of configured converters to extend
744740
* @since 4.1.3
745741
*/
746742
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
747743
}
748744

749745
/**
750746
* Adds a set of default HttpMessageConverter instances to the given list.
751-
* Subclasses can call this method from {@link #configureMessageConverters(List)}.
747+
* Subclasses can call this method from {@link #configureMessageConverters}.
752748
* @param messageConverters the list to add the default message converters to
753749
*/
754750
protected final void addDefaultHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
@@ -813,14 +809,12 @@ public SimpleControllerHandlerAdapter simpleControllerHandlerAdapter() {
813809
}
814810

815811
/**
816-
* Returns a {@link HandlerExceptionResolverComposite} containing a list
817-
* of exception resolvers obtained either through
818-
* {@link #configureHandlerExceptionResolvers(List)} or through
819-
* {@link #addDefaultHandlerExceptionResolvers(List)}.
820-
* <p><strong>Note:</strong> This method cannot be made final due to CGLib
821-
* constraints. Rather than overriding it, consider overriding
822-
* {@link #configureHandlerExceptionResolvers(List)}, which allows
823-
* providing a list of resolvers.
812+
* Returns a {@link HandlerExceptionResolverComposite} containing a list of exception
813+
* resolvers obtained either through {@link #configureHandlerExceptionResolvers} or
814+
* through {@link #addDefaultHandlerExceptionResolvers}.
815+
* <p><strong>Note:</strong> This method cannot be made final due to CGLIB constraints.
816+
* Rather than overriding it, consider overriding {@link #configureHandlerExceptionResolvers}
817+
* which allows for providing a list of resolvers.
824818
*/
825819
@Bean
826820
public HandlerExceptionResolver handlerExceptionResolver() {
@@ -838,29 +832,29 @@ public HandlerExceptionResolver handlerExceptionResolver() {
838832

839833
/**
840834
* Override this method to configure the list of
841-
* {@link HandlerExceptionResolver}s to use. Adding resolvers to the list
842-
* turns off the default resolvers that would otherwise be registered by
843-
* default. Also see {@link #addDefaultHandlerExceptionResolvers(List)}
835+
* {@link HandlerExceptionResolver HandlerExceptionResolvers} to use.
836+
* <p>Adding resolvers to the list turns off the default resolvers that would otherwise
837+
* be registered by default. Also see {@link #addDefaultHandlerExceptionResolvers}
844838
* that can be used to add the default exception resolvers.
845-
* @param exceptionResolvers a list to add exception resolvers to;
846-
* initially an empty list.
839+
* @param exceptionResolvers a list to add exception resolvers to (initially an empty list)
847840
*/
848841
protected void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
849842
}
850843

851844
/**
852845
* Override this method to extend or modify the list of
853-
* {@link HandlerExceptionResolver}s after it has been configured. This may
854-
* be useful for example to allow default resolvers to be registered and then
855-
* insert a custom one through this method.
846+
* {@link HandlerExceptionResolver HandlerExceptionResolvers} after it has been configured.
847+
* <p>This may be useful for example to allow default resolvers to be registered
848+
* and then insert a custom one through this method.
856849
* @param exceptionResolvers the list of configured resolvers to extend.
857850
* @since 4.3
858851
*/
859852
protected void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
860853
}
861854

862855
/**
863-
* A method available to subclasses for adding default {@link HandlerExceptionResolver}s.
856+
* A method available to subclasses for adding default
857+
* {@link HandlerExceptionResolver HandlerExceptionResolvers}.
864858
* <p>Adds the following exception resolvers:
865859
* <ul>
866860
* <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions through
@@ -963,7 +957,8 @@ protected final Map<String, CorsConfiguration> getCorsConfigurations() {
963957
protected void addCorsMappings(CorsRegistry registry) {
964958
}
965959

966-
@Bean @Lazy
960+
@Bean
961+
@Lazy
967962
public HandlerMappingIntrospector mvcHandlerMappingIntrospector() {
968963
return new HandlerMappingIntrospector();
969964
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -109,6 +109,13 @@ public void setContentNegotiationManager(ContentNegotiationManager contentNegoti
109109
this.contentNegotiationManager = contentNegotiationManager;
110110
}
111111

112+
/**
113+
* Return the configured {@link ContentNegotiationManager}.
114+
*/
115+
public ContentNegotiationManager getContentNegotiationManager() {
116+
return this.contentNegotiationManager;
117+
}
118+
112119
@Override
113120
public void setEmbeddedValueResolver(StringValueResolver resolver) {
114121
this.embeddedValueResolver = resolver;
@@ -149,13 +156,6 @@ public boolean useTrailingSlashMatch() {
149156
return this.useTrailingSlashMatch;
150157
}
151158

152-
/**
153-
* Return the configured {@link ContentNegotiationManager}.
154-
*/
155-
public ContentNegotiationManager getContentNegotiationManager() {
156-
return this.contentNegotiationManager;
157-
}
158-
159159
/**
160160
* Return the file extensions to use for suffix pattern matching.
161161
*/
@@ -166,7 +166,8 @@ public List<String> getFileExtensions() {
166166

167167
/**
168168
* {@inheritDoc}
169-
* Expects a handler to have a type-level @{@link Controller} annotation.
169+
* <p>Expects a handler to have either a type-level @{@link Controller}
170+
* annotation or a type-level @{@link RequestMapping} annotation.
170171
*/
171172
@Override
172173
protected boolean isHandler(Class<?> beanType) {

0 commit comments

Comments
 (0)