Skip to content

Commit 70424a7

Browse files
committed
Polishing
1 parent 318d04c commit 70424a7

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
* <li>the {@link HandlerMapping} for ViewControllers
122122
* <li>and the {@link HandlerMapping} for serving resources
123123
* </ul>
124-
* Note that those beans can be configured by using the {@code path-matching} MVC namespace element.
124+
* Note that those beans can be configured by using the {@code path-matching}
125+
* MVC namespace element.
125126
*
126127
* <p>Both the {@link RequestMappingHandlerAdapter} and the
127128
* {@link ExceptionHandlerExceptionResolver} are configured with instances of
@@ -131,7 +132,7 @@
131132
* <li>A {@link DefaultFormattingConversionService}
132133
* <li>A {@link org.springframework.validation.beanvalidation.LocalValidatorFactoryBean}
133134
* if a JSR-303 implementation is available on the classpath
134-
* <li>A range of {@link HttpMessageConverter}s depending on what 3rd party
135+
* <li>A range of {@link HttpMessageConverter}s depending on which third-party
135136
* libraries are available on the classpath.
136137
* </ul>
137138
*
@@ -265,22 +266,23 @@ else if (element.hasAttribute("ignoreDefaultModelOnRedirect")) {
265266
handlerAdapterDef.getPropertyValues().add("deferredResultInterceptors", deferredResultInterceptors);
266267
readerContext.getRegistry().registerBeanDefinition(HANDLER_ADAPTER_BEAN_NAME , handlerAdapterDef);
267268

268-
String uriCompContribName = MvcUriComponentsBuilder.MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME;
269-
RootBeanDefinition uriCompContribDef = new RootBeanDefinition(CompositeUriComponentsContributorFactoryBean.class);
270-
uriCompContribDef.setSource(source);
271-
uriCompContribDef.getPropertyValues().addPropertyValue("handlerAdapter", handlerAdapterDef);
272-
uriCompContribDef.getPropertyValues().addPropertyValue("conversionService", conversionService);
273-
readerContext.getRegistry().registerBeanDefinition(uriCompContribName, uriCompContribDef);
269+
RootBeanDefinition uriContributorDef =
270+
new RootBeanDefinition(CompositeUriComponentsContributorFactoryBean.class);
271+
uriContributorDef.setSource(source);
272+
uriContributorDef.getPropertyValues().addPropertyValue("handlerAdapter", handlerAdapterDef);
273+
uriContributorDef.getPropertyValues().addPropertyValue("conversionService", conversionService);
274+
String uriContributorName = MvcUriComponentsBuilder.MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME;
275+
readerContext.getRegistry().registerBeanDefinition(uriContributorName, uriContributorDef);
274276

275277
RootBeanDefinition csInterceptorDef = new RootBeanDefinition(ConversionServiceExposingInterceptor.class);
276278
csInterceptorDef.setSource(source);
277279
csInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, conversionService);
278-
RootBeanDefinition mappedCsInterceptorDef = new RootBeanDefinition(MappedInterceptor.class);
279-
mappedCsInterceptorDef.setSource(source);
280-
mappedCsInterceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
281-
mappedCsInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, (Object) null);
282-
mappedCsInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, csInterceptorDef);
283-
String mappedInterceptorName = readerContext.registerWithGeneratedName(mappedCsInterceptorDef);
280+
RootBeanDefinition mappedInterceptorDef = new RootBeanDefinition(MappedInterceptor.class);
281+
mappedInterceptorDef.setSource(source);
282+
mappedInterceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
283+
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, (Object) null);
284+
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, csInterceptorDef);
285+
String mappedInterceptorName = readerContext.registerWithGeneratedName(mappedInterceptorDef);
284286

285287
RootBeanDefinition methodExceptionResolver = new RootBeanDefinition(ExceptionHandlerExceptionResolver.class);
286288
methodExceptionResolver.setSource(source);
@@ -386,7 +388,6 @@ private RuntimeBeanReference getContentNegotiationManager(
386388
factoryBeanDef.setSource(source);
387389
factoryBeanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
388390
factoryBeanDef.getPropertyValues().add("mediaTypes", getDefaultMediaTypes());
389-
390391
String name = CONTENT_NEGOTIATION_MANAGER_BEAN_NAME;
391392
parserContext.getReaderContext().getRegistry().registerBeanDefinition(name , factoryBeanDef);
392393
parserContext.registerComponent(new BeanComponentDefinition(factoryBeanDef, name));
@@ -401,6 +402,7 @@ private void configurePathMatchingProperties(
401402
Element pathMatchingElement = DomUtils.getChildElementByTagName(element, "path-matching");
402403
if (pathMatchingElement != null) {
403404
Object source = parserContext.extractSource(element);
405+
404406
if (pathMatchingElement.hasAttribute("suffix-pattern")) {
405407
Boolean useSuffixPatternMatch = Boolean.valueOf(pathMatchingElement.getAttribute("suffix-pattern"));
406408
handlerMappingDef.getPropertyValues().add("useSuffixPatternMatch", useSuffixPatternMatch);
@@ -413,6 +415,7 @@ private void configurePathMatchingProperties(
413415
Boolean useRegisteredSuffixPatternMatch = Boolean.valueOf(pathMatchingElement.getAttribute("registered-suffixes-only"));
414416
handlerMappingDef.getPropertyValues().add("useRegisteredSuffixPatternMatch", useRegisteredSuffixPatternMatch);
415417
}
418+
416419
RuntimeBeanReference pathHelperRef = null;
417420
if (pathMatchingElement.hasAttribute("path-helper")) {
418421
pathHelperRef = new RuntimeBeanReference(pathMatchingElement.getAttribute("path-helper"));
@@ -430,18 +433,18 @@ private void configurePathMatchingProperties(
430433
}
431434

432435
private Properties getDefaultMediaTypes() {
433-
Properties props = new Properties();
436+
Properties defaultMediaTypes = new Properties();
434437
if (romePresent) {
435-
props.put("atom", MediaType.APPLICATION_ATOM_XML_VALUE);
436-
props.put("rss", MediaType.APPLICATION_RSS_XML_VALUE);
438+
defaultMediaTypes.put("atom", MediaType.APPLICATION_ATOM_XML_VALUE);
439+
defaultMediaTypes.put("rss", MediaType.APPLICATION_RSS_XML_VALUE);
437440
}
438441
if (jaxb2Present || jackson2XmlPresent) {
439-
props.put("xml", MediaType.APPLICATION_XML_VALUE);
442+
defaultMediaTypes.put("xml", MediaType.APPLICATION_XML_VALUE);
440443
}
441444
if (jackson2Present || gsonPresent) {
442-
props.put("json", MediaType.APPLICATION_JSON_VALUE);
445+
defaultMediaTypes.put("json", MediaType.APPLICATION_JSON_VALUE);
443446
}
444-
return props;
447+
return defaultMediaTypes;
445448
}
446449

447450
private RuntimeBeanReference getMessageCodesResolver(Element element) {

0 commit comments

Comments
 (0)