128
128
* <li>the {@link HandlerMapping} for ViewControllers
129
129
* <li>and the {@link HandlerMapping} for serving resources
130
130
* </ul>
131
- * Note that those beans can be configured by using the {@code path-matching} MVC namespace element.
131
+ * Note that those beans can be configured by using the {@code path-matching}
132
+ * MVC namespace element.
132
133
*
133
134
* <p>Both the {@link RequestMappingHandlerAdapter} and the
134
135
* {@link ExceptionHandlerExceptionResolver} are configured with instances of
138
139
* <li>A {@link DefaultFormattingConversionService}
139
140
* <li>A {@link org.springframework.validation.beanvalidation.LocalValidatorFactoryBean}
140
141
* if a JSR-303 implementation is available on the classpath
141
- * <li>A range of {@link HttpMessageConverter}s depending on what 3rd party
142
+ * <li>A range of {@link HttpMessageConverter}s depending on which third- party
142
143
* libraries are available on the classpath.
143
144
* </ul>
144
145
*
@@ -158,6 +159,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
158
159
159
160
public static final String CONTENT_NEGOTIATION_MANAGER_BEAN_NAME = "mvcContentNegotiationManager" ;
160
161
162
+
161
163
private static final boolean javaxValidationPresent =
162
164
ClassUtils .isPresent ("javax.validation.Validator" ,
163
165
AnnotationDrivenBeanDefinitionParser .class .getClassLoader ());
@@ -189,7 +191,8 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
189
191
AnnotationDrivenBeanDefinitionParser .class .getClassLoader ());
190
192
191
193
private static final boolean gsonPresent =
192
- ClassUtils .isPresent ("com.google.gson.Gson" , AnnotationDrivenBeanDefinitionParser .class .getClassLoader ());
194
+ ClassUtils .isPresent ("com.google.gson.Gson" ,
195
+ AnnotationDrivenBeanDefinitionParser .class .getClassLoader ());
193
196
194
197
195
198
@ Override
@@ -269,39 +272,38 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
269
272
handlerAdapterDef .getPropertyValues ().add ("deferredResultInterceptors" , deferredResultInterceptors );
270
273
readerContext .getRegistry ().registerBeanDefinition (HANDLER_ADAPTER_BEAN_NAME , handlerAdapterDef );
271
274
272
- String uriCompContribName = MvcUriComponentsBuilder .MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME ;
273
- RootBeanDefinition uriCompContribDef = new RootBeanDefinition (CompositeUriComponentsContributorFactoryBean .class );
274
- uriCompContribDef .setSource (source );
275
- uriCompContribDef .getPropertyValues ().addPropertyValue ("handlerAdapter" , handlerAdapterDef );
276
- uriCompContribDef .getPropertyValues ().addPropertyValue ("conversionService" , conversionService );
277
- readerContext .getRegistry ().registerBeanDefinition (uriCompContribName , uriCompContribDef );
275
+ RootBeanDefinition uriContributorDef =
276
+ new RootBeanDefinition (CompositeUriComponentsContributorFactoryBean .class );
277
+ uriContributorDef .setSource (source );
278
+ uriContributorDef .getPropertyValues ().addPropertyValue ("handlerAdapter" , handlerAdapterDef );
279
+ uriContributorDef .getPropertyValues ().addPropertyValue ("conversionService" , conversionService );
280
+ String uriContributorName = MvcUriComponentsBuilder .MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME ;
281
+ readerContext .getRegistry ().registerBeanDefinition (uriContributorName , uriContributorDef );
278
282
279
283
RootBeanDefinition csInterceptorDef = new RootBeanDefinition (ConversionServiceExposingInterceptor .class );
280
284
csInterceptorDef .setSource (source );
281
285
csInterceptorDef .getConstructorArgumentValues ().addIndexedArgumentValue (0 , conversionService );
282
- RootBeanDefinition mappedCsInterceptorDef = new RootBeanDefinition (MappedInterceptor .class );
283
- mappedCsInterceptorDef .setSource (source );
284
- mappedCsInterceptorDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
285
- mappedCsInterceptorDef .getConstructorArgumentValues ().addIndexedArgumentValue (0 , (Object ) null );
286
- mappedCsInterceptorDef .getConstructorArgumentValues ().addIndexedArgumentValue (1 , csInterceptorDef );
287
- String mappedInterceptorName = readerContext .registerWithGeneratedName (mappedCsInterceptorDef );
288
-
289
- RootBeanDefinition exceptionResolver = new RootBeanDefinition (ExceptionHandlerExceptionResolver .class );
290
- exceptionResolver .setSource (source );
291
- exceptionResolver .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
292
- exceptionResolver .getPropertyValues ().add ("contentNegotiationManager" , contentNegotiationManager );
293
- exceptionResolver .getPropertyValues ().add ("messageConverters" , messageConverters );
294
- exceptionResolver .getPropertyValues ().add ("order" , 0 );
295
- addResponseBodyAdvice (exceptionResolver );
296
-
286
+ RootBeanDefinition mappedInterceptorDef = new RootBeanDefinition (MappedInterceptor .class );
287
+ mappedInterceptorDef .setSource (source );
288
+ mappedInterceptorDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
289
+ mappedInterceptorDef .getConstructorArgumentValues ().addIndexedArgumentValue (0 , (Object ) null );
290
+ mappedInterceptorDef .getConstructorArgumentValues ().addIndexedArgumentValue (1 , csInterceptorDef );
291
+ String mappedInterceptorName = readerContext .registerWithGeneratedName (mappedInterceptorDef );
292
+
293
+ RootBeanDefinition methodExceptionResolver = new RootBeanDefinition (ExceptionHandlerExceptionResolver .class );
294
+ methodExceptionResolver .setSource (source );
295
+ methodExceptionResolver .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
296
+ methodExceptionResolver .getPropertyValues ().add ("contentNegotiationManager" , contentNegotiationManager );
297
+ methodExceptionResolver .getPropertyValues ().add ("messageConverters" , messageConverters );
298
+ methodExceptionResolver .getPropertyValues ().add ("order" , 0 );
299
+ addResponseBodyAdvice (methodExceptionResolver );
297
300
if (argumentResolvers != null ) {
298
- exceptionResolver .getPropertyValues ().add ("customArgumentResolvers" , argumentResolvers );
301
+ methodExceptionResolver .getPropertyValues ().add ("customArgumentResolvers" , argumentResolvers );
299
302
}
300
303
if (returnValueHandlers != null ) {
301
- exceptionResolver .getPropertyValues ().add ("customReturnValueHandlers" , returnValueHandlers );
304
+ methodExceptionResolver .getPropertyValues ().add ("customReturnValueHandlers" , returnValueHandlers );
302
305
}
303
-
304
- String methodExceptionResolverName = readerContext .registerWithGeneratedName (exceptionResolver );
306
+ String methodExResolverName = readerContext .registerWithGeneratedName (methodExceptionResolver );
305
307
306
308
RootBeanDefinition statusExceptionResolver = new RootBeanDefinition (ResponseStatusExceptionResolver .class );
307
309
statusExceptionResolver .setSource (source );
@@ -317,11 +319,11 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
317
319
318
320
parserContext .registerComponent (new BeanComponentDefinition (handlerMappingDef , HANDLER_MAPPING_BEAN_NAME ));
319
321
parserContext .registerComponent (new BeanComponentDefinition (handlerAdapterDef , HANDLER_ADAPTER_BEAN_NAME ));
320
- parserContext .registerComponent (new BeanComponentDefinition (uriCompContribDef , uriCompContribName ));
321
- parserContext .registerComponent (new BeanComponentDefinition (exceptionResolver , methodExceptionResolverName ));
322
+ parserContext .registerComponent (new BeanComponentDefinition (uriContributorDef , uriContributorName ));
323
+ parserContext .registerComponent (new BeanComponentDefinition (mappedInterceptorDef , mappedInterceptorName ));
324
+ parserContext .registerComponent (new BeanComponentDefinition (methodExceptionResolver , methodExResolverName ));
322
325
parserContext .registerComponent (new BeanComponentDefinition (statusExceptionResolver , statusExResolverName ));
323
326
parserContext .registerComponent (new BeanComponentDefinition (defaultExceptionResolver , defaultExResolverName ));
324
- parserContext .registerComponent (new BeanComponentDefinition (mappedCsInterceptorDef , mappedInterceptorName ));
325
327
326
328
// Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
327
329
MvcNamespaceUtils .registerDefaultComponents (parserContext , source );
@@ -382,8 +384,8 @@ else if (javaxValidationPresent) {
382
384
}
383
385
}
384
386
385
- private RuntimeBeanReference getContentNegotiationManager (Element element , @ Nullable Object source ,
386
- ParserContext parserContext ) {
387
+ private RuntimeBeanReference getContentNegotiationManager (
388
+ Element element , @ Nullable Object source , ParserContext parserContext ) {
387
389
388
390
RuntimeBeanReference beanRef ;
389
391
if (element .hasAttribute ("content-negotiation-manager" )) {
@@ -395,7 +397,6 @@ private RuntimeBeanReference getContentNegotiationManager(Element element, @Null
395
397
factoryBeanDef .setSource (source );
396
398
factoryBeanDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
397
399
factoryBeanDef .getPropertyValues ().add ("mediaTypes" , getDefaultMediaTypes ());
398
-
399
400
String name = CONTENT_NEGOTIATION_MANAGER_BEAN_NAME ;
400
401
parserContext .getReaderContext ().getRegistry ().registerBeanDefinition (name , factoryBeanDef );
401
402
parserContext .registerComponent (new BeanComponentDefinition (factoryBeanDef , name ));
@@ -404,12 +405,13 @@ private RuntimeBeanReference getContentNegotiationManager(Element element, @Null
404
405
return beanRef ;
405
406
}
406
407
407
- private void configurePathMatchingProperties (RootBeanDefinition handlerMappingDef , Element element ,
408
- ParserContext parserContext ) {
408
+ private void configurePathMatchingProperties (
409
+ RootBeanDefinition handlerMappingDef , Element element , ParserContext parserContext ) {
409
410
410
411
Element pathMatchingElement = DomUtils .getChildElementByTagName (element , "path-matching" );
411
412
if (pathMatchingElement != null ) {
412
413
Object source = parserContext .extractSource (element );
414
+
413
415
if (pathMatchingElement .hasAttribute ("suffix-pattern" )) {
414
416
Boolean useSuffixPatternMatch = Boolean .valueOf (pathMatchingElement .getAttribute ("suffix-pattern" ));
415
417
handlerMappingDef .getPropertyValues ().add ("useSuffixPatternMatch" , useSuffixPatternMatch );
@@ -422,6 +424,7 @@ private void configurePathMatchingProperties(RootBeanDefinition handlerMappingDe
422
424
Boolean useRegisteredSuffixPatternMatch = Boolean .valueOf (pathMatchingElement .getAttribute ("registered-suffixes-only" ));
423
425
handlerMappingDef .getPropertyValues ().add ("useRegisteredSuffixPatternMatch" , useRegisteredSuffixPatternMatch );
424
426
}
427
+
425
428
RuntimeBeanReference pathHelperRef = null ;
426
429
if (pathMatchingElement .hasAttribute ("path-helper" )) {
427
430
pathHelperRef = new RuntimeBeanReference (pathMatchingElement .getAttribute ("path-helper" ));
@@ -439,24 +442,24 @@ private void configurePathMatchingProperties(RootBeanDefinition handlerMappingDe
439
442
}
440
443
441
444
private Properties getDefaultMediaTypes () {
442
- Properties props = new Properties ();
445
+ Properties defaultMediaTypes = new Properties ();
443
446
if (romePresent ) {
444
- props .put ("atom" , MediaType .APPLICATION_ATOM_XML_VALUE );
445
- props .put ("rss" , MediaType .APPLICATION_RSS_XML_VALUE );
447
+ defaultMediaTypes .put ("atom" , MediaType .APPLICATION_ATOM_XML_VALUE );
448
+ defaultMediaTypes .put ("rss" , MediaType .APPLICATION_RSS_XML_VALUE );
446
449
}
447
450
if (jaxb2Present || jackson2XmlPresent ) {
448
- props .put ("xml" , MediaType .APPLICATION_XML_VALUE );
451
+ defaultMediaTypes .put ("xml" , MediaType .APPLICATION_XML_VALUE );
449
452
}
450
453
if (jackson2Present || gsonPresent ) {
451
- props .put ("json" , MediaType .APPLICATION_JSON_VALUE );
454
+ defaultMediaTypes .put ("json" , MediaType .APPLICATION_JSON_VALUE );
452
455
}
453
456
if (jackson2SmilePresent ) {
454
- props .put ("smile" , "application/x-jackson-smile" );
457
+ defaultMediaTypes .put ("smile" , "application/x-jackson-smile" );
455
458
}
456
459
if (jackson2CborPresent ) {
457
- props .put ("cbor" , "application/cbor" );
460
+ defaultMediaTypes .put ("cbor" , "application/cbor" );
458
461
}
459
- return props ;
462
+ return defaultMediaTypes ;
460
463
}
461
464
462
465
@ Nullable
@@ -472,7 +475,7 @@ private RuntimeBeanReference getMessageCodesResolver(Element element) {
472
475
@ Nullable
473
476
private String getAsyncTimeout (Element element ) {
474
477
Element asyncElement = DomUtils .getChildElementByTagName (element , "async-support" );
475
- return (asyncElement != null ) ? asyncElement .getAttribute ("default-timeout" ) : null ;
478
+ return (asyncElement != null ? asyncElement .getAttribute ("default-timeout" ) : null ) ;
476
479
}
477
480
478
481
@ Nullable
@@ -649,7 +652,6 @@ private RootBeanDefinition createConverterDefinition(Class<?> converterClass, @N
649
652
return beanDefinition ;
650
653
}
651
654
652
-
653
655
private ManagedList <Object > extractBeanSubElements (Element parentElement , ParserContext parserContext ) {
654
656
ManagedList <Object > list = new ManagedList <>();
655
657
list .setSource (parserContext .extractSource (parentElement ));
@@ -695,7 +697,7 @@ public void afterPropertiesSet() {
695
697
696
698
@ Override
697
699
@ Nullable
698
- public CompositeUriComponentsContributor getObject () throws Exception {
700
+ public CompositeUriComponentsContributor getObject () {
699
701
return this .uriComponentsContributor ;
700
702
}
701
703
0 commit comments