16
16
17
17
package org .springframework .web .servlet .config ;
18
18
19
- import org .w3c .dom .Element ;
20
-
21
19
import org .springframework .beans .factory .config .BeanDefinition ;
22
20
import org .springframework .beans .factory .config .RuntimeBeanReference ;
23
21
import org .springframework .beans .factory .parsing .BeanComponentDefinition ;
40
38
import org .springframework .web .bind .support .ConfigurableWebBindingInitializer ;
41
39
import org .springframework .web .servlet .mvc .annotation .AnnotationMethodHandlerAdapter ;
42
40
import org .springframework .web .servlet .mvc .annotation .DefaultAnnotationHandlerMapping ;
41
+ import org .w3c .dom .Element ;
43
42
44
43
/**
45
44
* {@link BeanDefinitionParser} that parses the {@code annotation-driven} element to configure a Spring MVC web
@@ -85,24 +84,28 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
85
84
public BeanDefinition parse (Element element , ParserContext parserContext ) {
86
85
Object source = parserContext .extractSource (element );
87
86
87
+ CompositeComponentDefinition compDefinition = new CompositeComponentDefinition (element .getTagName (), source );
88
+ parserContext .pushContainingComponent (compDefinition );
89
+
88
90
RootBeanDefinition annMappingDef = new RootBeanDefinition (DefaultAnnotationHandlerMapping .class );
89
91
annMappingDef .setSource (source );
92
+ annMappingDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
90
93
annMappingDef .getPropertyValues ().add ("order" , 0 );
91
94
String annMappingName = parserContext .getReaderContext ().registerWithGeneratedName (annMappingDef );
92
95
93
96
RootBeanDefinition bindingDef = new RootBeanDefinition (ConfigurableWebBindingInitializer .class );
94
97
bindingDef .setSource (source );
98
+ bindingDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
95
99
bindingDef .getPropertyValues ().add ("conversionService" , getConversionService (element , source , parserContext ));
96
100
bindingDef .getPropertyValues ().add ("validator" , getValidator (element , source , parserContext ));
97
101
98
102
RootBeanDefinition annAdapterDef = new RootBeanDefinition (AnnotationMethodHandlerAdapter .class );
99
103
annAdapterDef .setSource (source );
104
+ annAdapterDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
100
105
annAdapterDef .getPropertyValues ().add ("webBindingInitializer" , bindingDef );
101
106
annAdapterDef .getPropertyValues ().add ("messageConverters" , getMessageConverters (source ));
102
107
String adapterName = parserContext .getReaderContext ().registerWithGeneratedName (annAdapterDef );
103
-
104
- CompositeComponentDefinition compDefinition = new CompositeComponentDefinition (element .getTagName (), source );
105
- parserContext .pushContainingComponent (compDefinition );
108
+
106
109
parserContext .registerComponent (new BeanComponentDefinition (annMappingDef , annMappingName ));
107
110
parserContext .registerComponent (new BeanComponentDefinition (annAdapterDef , adapterName ));
108
111
parserContext .popAndRegisterContainingComponent ();
@@ -118,7 +121,9 @@ private Object getConversionService(Element element, Object source, ParserContex
118
121
else {
119
122
RootBeanDefinition conversionDef = new RootBeanDefinition (FormattingConversionServiceFactoryBean .class );
120
123
conversionDef .setSource (source );
124
+ conversionDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
121
125
String conversionName = parserContext .getReaderContext ().registerWithGeneratedName (conversionDef );
126
+ parserContext .registerComponent (new BeanComponentDefinition (conversionDef , conversionName ));
122
127
return new RuntimeBeanReference (conversionName );
123
128
}
124
129
}
@@ -130,7 +135,9 @@ private Object getValidator(Element element, Object source, ParserContext parser
130
135
else if (jsr303Present ) {
131
136
RootBeanDefinition validatorDef = new RootBeanDefinition (LocalValidatorFactoryBean .class );
132
137
validatorDef .setSource (source );
138
+ validatorDef .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
133
139
String validatorName = parserContext .getReaderContext ().registerWithGeneratedName (validatorDef );
140
+ parserContext .registerComponent (new BeanComponentDefinition (validatorDef , validatorName ));
134
141
return new RuntimeBeanReference (validatorName );
135
142
}
136
143
else {
0 commit comments