34
34
import org .springframework .beans .factory .support .RootBeanDefinition ;
35
35
import org .springframework .beans .factory .xml .BeanDefinitionParser ;
36
36
import org .springframework .beans .factory .xml .ParserContext ;
37
+ import org .springframework .beans .factory .xml .XmlReaderContext ;
37
38
import org .springframework .core .convert .ConversionService ;
38
39
import org .springframework .format .support .DefaultFormattingConversionService ;
39
40
import org .springframework .format .support .FormattingConversionServiceFactoryBean ;
147
148
*/
148
149
class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
149
150
151
+ public static final String HANDLER_MAPPING_BEAN_NAME = RequestMappingHandlerMapping .class .getName ();
152
+
153
+ public static final String HANDLER_ADAPTER_BEAN_NAME = RequestMappingHandlerAdapter .class .getName ();
154
+
150
155
public static final String CONTENT_NEGOTIATION_MANAGER_BEAN_NAME = "mvcContentNegotiationManager" ;
151
156
152
157
private static final boolean javaxValidationPresent =
@@ -172,6 +177,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
172
177
@ Override
173
178
public BeanDefinition parse (Element element , ParserContext parserContext ) {
174
179
Object source = parserContext .extractSource (element );
180
+ XmlReaderContext readerContext = parserContext .getReaderContext ();
175
181
176
182
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition (element .getTagName (), source );
177
183
parserContext .pushContainingComponent (compDefinition );
@@ -183,7 +189,6 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
183
189
handlerMappingDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
184
190
handlerMappingDef .getPropertyValues ().add ("order" , 0 );
185
191
handlerMappingDef .getPropertyValues ().add ("contentNegotiationManager" , contentNegotiationManager );
186
- String methodMappingName = parserContext .getReaderContext ().registerWithGeneratedName (handlerMappingDef );
187
192
188
193
if (element .hasAttribute ("enable-matrix-variables" )) {
189
194
Boolean enableMatrixVariables = Boolean .valueOf (element .getAttribute ("enable-matrix-variables" ));
@@ -195,6 +200,7 @@ else if (element.hasAttribute("enableMatrixVariables")) {
195
200
}
196
201
197
202
configurePathMatchingProperties (handlerMappingDef , element , parserContext );
203
+ readerContext .getRegistry ().registerBeanDefinition (HANDLER_MAPPING_BEAN_NAME , handlerMappingDef );
198
204
199
205
RuntimeBeanReference conversionService = getConversionService (element , source , parserContext );
200
206
RuntimeBeanReference validator = getValidator (element , source , parserContext );
@@ -248,14 +254,14 @@ else if (element.hasAttribute("ignoreDefaultModelOnRedirect")) {
248
254
249
255
handlerAdapterDef .getPropertyValues ().add ("callableInterceptors" , callableInterceptors );
250
256
handlerAdapterDef .getPropertyValues ().add ("deferredResultInterceptors" , deferredResultInterceptors );
251
- String handlerAdapterName = parserContext . getReaderContext ().registerWithGeneratedName ( handlerAdapterDef );
257
+ readerContext . getRegistry ().registerBeanDefinition ( HANDLER_ADAPTER_BEAN_NAME , handlerAdapterDef );
252
258
253
259
String uriCompContribName = MvcUriComponentsBuilder .MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME ;
254
260
RootBeanDefinition uriCompContribDef = new RootBeanDefinition (CompositeUriComponentsContributorFactoryBean .class );
255
261
uriCompContribDef .setSource (source );
256
262
uriCompContribDef .getPropertyValues ().addPropertyValue ("handlerAdapter" , handlerAdapterDef );
257
263
uriCompContribDef .getPropertyValues ().addPropertyValue ("conversionService" , conversionService );
258
- parserContext . getReaderContext () .getRegistry ().registerBeanDefinition (uriCompContribName , uriCompContribDef );
264
+ readerContext .getRegistry ().registerBeanDefinition (uriCompContribName , uriCompContribDef );
259
265
260
266
RootBeanDefinition csInterceptorDef = new RootBeanDefinition (ConversionServiceExposingInterceptor .class );
261
267
csInterceptorDef .setSource (source );
@@ -265,7 +271,7 @@ else if (element.hasAttribute("ignoreDefaultModelOnRedirect")) {
265
271
mappedCsInterceptorDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
266
272
mappedCsInterceptorDef .getConstructorArgumentValues ().addIndexedArgumentValue (0 , (Object ) null );
267
273
mappedCsInterceptorDef .getConstructorArgumentValues ().addIndexedArgumentValue (1 , csInterceptorDef );
268
- String mappedInterceptorName = parserContext . getReaderContext () .registerWithGeneratedName (mappedCsInterceptorDef );
274
+ String mappedInterceptorName = readerContext .registerWithGeneratedName (mappedCsInterceptorDef );
269
275
270
276
RootBeanDefinition exceptionHandlerExceptionResolver = new RootBeanDefinition (ExceptionHandlerExceptionResolver .class );
271
277
exceptionHandlerExceptionResolver .setSource (source );
@@ -275,25 +281,24 @@ else if (element.hasAttribute("ignoreDefaultModelOnRedirect")) {
275
281
exceptionHandlerExceptionResolver .getPropertyValues ().add ("order" , 0 );
276
282
addResponseBodyAdvice (exceptionHandlerExceptionResolver );
277
283
278
- String methodExceptionResolverName =
279
- parserContext .getReaderContext ().registerWithGeneratedName (exceptionHandlerExceptionResolver );
284
+ String methodExceptionResolverName = readerContext .registerWithGeneratedName (exceptionHandlerExceptionResolver );
280
285
281
286
RootBeanDefinition responseStatusExceptionResolver = new RootBeanDefinition (ResponseStatusExceptionResolver .class );
282
287
responseStatusExceptionResolver .setSource (source );
283
288
responseStatusExceptionResolver .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
284
289
responseStatusExceptionResolver .getPropertyValues ().add ("order" , 1 );
285
290
String responseStatusExceptionResolverName =
286
- parserContext . getReaderContext () .registerWithGeneratedName (responseStatusExceptionResolver );
291
+ readerContext .registerWithGeneratedName (responseStatusExceptionResolver );
287
292
288
293
RootBeanDefinition defaultExceptionResolver = new RootBeanDefinition (DefaultHandlerExceptionResolver .class );
289
294
defaultExceptionResolver .setSource (source );
290
295
defaultExceptionResolver .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
291
296
defaultExceptionResolver .getPropertyValues ().add ("order" , 2 );
292
297
String defaultExceptionResolverName =
293
- parserContext . getReaderContext () .registerWithGeneratedName (defaultExceptionResolver );
298
+ readerContext .registerWithGeneratedName (defaultExceptionResolver );
294
299
295
- parserContext .registerComponent (new BeanComponentDefinition (handlerMappingDef , methodMappingName ));
296
- parserContext .registerComponent (new BeanComponentDefinition (handlerAdapterDef , handlerAdapterName ));
300
+ parserContext .registerComponent (new BeanComponentDefinition (handlerMappingDef , HANDLER_MAPPING_BEAN_NAME ));
301
+ parserContext .registerComponent (new BeanComponentDefinition (handlerAdapterDef , HANDLER_ADAPTER_BEAN_NAME ));
297
302
parserContext .registerComponent (new BeanComponentDefinition (uriCompContribDef , uriCompContribName ));
298
303
parserContext .registerComponent (new BeanComponentDefinition (exceptionHandlerExceptionResolver , methodExceptionResolverName ));
299
304
parserContext .registerComponent (new BeanComponentDefinition (responseStatusExceptionResolver , responseStatusExceptionResolverName ));
@@ -349,14 +354,13 @@ else if (javaxValidationPresent) {
349
354
}
350
355
}
351
356
352
- private RuntimeBeanReference getContentNegotiationManager (Element element , Object source , ParserContext parserContext ) {
353
- RuntimeBeanReference contentNegotiationManagerRef ;
357
+ private RuntimeBeanReference getContentNegotiationManager (Element element , Object source ,
358
+ ParserContext parserContext ) {
359
+
360
+ RuntimeBeanReference beanRef ;
354
361
if (element .hasAttribute ("content-negotiation-manager" )) {
355
362
String name = element .getAttribute ("content-negotiation-manager" );
356
- contentNegotiationManagerRef = new RuntimeBeanReference (name );
357
- if (!CONTENT_NEGOTIATION_MANAGER_BEAN_NAME .equals (name )) {
358
- parserContext .getRegistry ().registerAlias (name , CONTENT_NEGOTIATION_MANAGER_BEAN_NAME );
359
- }
363
+ beanRef = new RuntimeBeanReference (name );
360
364
}
361
365
else {
362
366
RootBeanDefinition factoryBeanDef = new RootBeanDefinition (ContentNegotiationManagerFactoryBean .class );
@@ -367,13 +371,14 @@ private RuntimeBeanReference getContentNegotiationManager(Element element, Objec
367
371
String name = CONTENT_NEGOTIATION_MANAGER_BEAN_NAME ;
368
372
parserContext .getReaderContext ().getRegistry ().registerBeanDefinition (name , factoryBeanDef );
369
373
parserContext .registerComponent (new BeanComponentDefinition (factoryBeanDef , name ));
370
- contentNegotiationManagerRef = new RuntimeBeanReference (name );
374
+ beanRef = new RuntimeBeanReference (name );
371
375
}
372
- return contentNegotiationManagerRef ;
376
+ return beanRef ;
373
377
}
374
378
375
- private void configurePathMatchingProperties (RootBeanDefinition handlerMappingDef ,
376
- Element element , ParserContext parserContext ) {
379
+ private void configurePathMatchingProperties (RootBeanDefinition handlerMappingDef , Element element ,
380
+ ParserContext parserContext ) {
381
+
377
382
Element pathMatchingElement = DomUtils .getChildElementByTagName (element , "path-matching" );
378
383
if (pathMatchingElement != null ) {
379
384
Object source = parserContext .extractSource (element );
0 commit comments