Skip to content

Commit 7c6c1c3

Browse files
committed
some minor adjustments to the mvc namespace to make it work in the tools
1 parent 14b6914 commit 7c6c1c3

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.web.servlet.config;
1818

19-
import org.w3c.dom.Element;
20-
2119
import org.springframework.beans.factory.config.BeanDefinition;
2220
import org.springframework.beans.factory.config.RuntimeBeanReference;
2321
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
@@ -40,6 +38,7 @@
4038
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
4139
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
4240
import org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping;
41+
import org.w3c.dom.Element;
4342

4443
/**
4544
* {@link BeanDefinitionParser} that parses the {@code annotation-driven} element to configure a Spring MVC web
@@ -85,24 +84,28 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
8584
public BeanDefinition parse(Element element, ParserContext parserContext) {
8685
Object source = parserContext.extractSource(element);
8786

87+
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
88+
parserContext.pushContainingComponent(compDefinition);
89+
8890
RootBeanDefinition annMappingDef = new RootBeanDefinition(DefaultAnnotationHandlerMapping.class);
8991
annMappingDef.setSource(source);
92+
annMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
9093
annMappingDef.getPropertyValues().add("order", 0);
9194
String annMappingName = parserContext.getReaderContext().registerWithGeneratedName(annMappingDef);
9295

9396
RootBeanDefinition bindingDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
9497
bindingDef.setSource(source);
98+
bindingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
9599
bindingDef.getPropertyValues().add("conversionService", getConversionService(element, source, parserContext));
96100
bindingDef.getPropertyValues().add("validator", getValidator(element, source, parserContext));
97101

98102
RootBeanDefinition annAdapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
99103
annAdapterDef.setSource(source);
104+
annAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
100105
annAdapterDef.getPropertyValues().add("webBindingInitializer", bindingDef);
101106
annAdapterDef.getPropertyValues().add("messageConverters", getMessageConverters(source));
102107
String adapterName = parserContext.getReaderContext().registerWithGeneratedName(annAdapterDef);
103-
104-
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
105-
parserContext.pushContainingComponent(compDefinition);
108+
106109
parserContext.registerComponent(new BeanComponentDefinition(annMappingDef, annMappingName));
107110
parserContext.registerComponent(new BeanComponentDefinition(annAdapterDef, adapterName));
108111
parserContext.popAndRegisterContainingComponent();
@@ -118,7 +121,9 @@ private Object getConversionService(Element element, Object source, ParserContex
118121
else {
119122
RootBeanDefinition conversionDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
120123
conversionDef.setSource(source);
124+
conversionDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
121125
String conversionName = parserContext.getReaderContext().registerWithGeneratedName(conversionDef);
126+
parserContext.registerComponent(new BeanComponentDefinition(conversionDef, conversionName));
122127
return new RuntimeBeanReference(conversionName);
123128
}
124129
}
@@ -130,7 +135,9 @@ private Object getValidator(Element element, Object source, ParserContext parser
130135
else if (jsr303Present) {
131136
RootBeanDefinition validatorDef = new RootBeanDefinition(LocalValidatorFactoryBean.class);
132137
validatorDef.setSource(source);
138+
validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
133139
String validatorName = parserContext.getReaderContext().registerWithGeneratedName(validatorDef);
140+
parserContext.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));
134141
return new RuntimeBeanReference(validatorName);
135142
}
136143
else {

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/InterceptorsBeanDefinitionParser.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import org.springframework.beans.factory.config.BeanDefinition;
2222
import org.springframework.beans.factory.config.BeanDefinitionHolder;
23+
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
24+
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
2325
import org.springframework.beans.factory.support.RootBeanDefinition;
2426
import org.springframework.beans.factory.xml.BeanDefinitionParser;
2527
import org.springframework.beans.factory.xml.ParserContext;
@@ -37,10 +39,14 @@
3739
class InterceptorsBeanDefinitionParser implements BeanDefinitionParser {
3840

3941
public BeanDefinition parse(Element element, ParserContext parserContext) {
42+
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
43+
parserContext.pushContainingComponent(compDefinition);
44+
4045
List<Element> interceptors = DomUtils.getChildElementsByTagName(element, new String[] { "bean", "interceptor" });
4146
for (Element interceptor : interceptors) {
4247
RootBeanDefinition mappedInterceptorDef = new RootBeanDefinition(MappedInterceptor.class);
4348
mappedInterceptorDef.setSource(parserContext.extractSource(interceptor));
49+
mappedInterceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
4450
String[] pathPatterns;
4551
BeanDefinitionHolder interceptorDef;
4652
if ("interceptor".equals(interceptor.getLocalName())) {
@@ -59,8 +65,11 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
5965
}
6066
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, pathPatterns);
6167
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, interceptorDef);
62-
parserContext.getReaderContext().registerWithGeneratedName(mappedInterceptorDef);
68+
String mappedInterceptorName = parserContext.getReaderContext().registerWithGeneratedName(mappedInterceptorDef);
69+
parserContext.registerComponent(new BeanComponentDefinition(mappedInterceptorDef, mappedInterceptorName));
6370
}
71+
72+
parserContext.popAndRegisterContainingComponent();
6473
return null;
6574
}
6675

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020

2121
import org.springframework.beans.factory.config.BeanDefinition;
22+
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
2223
import org.springframework.beans.factory.support.ManagedMap;
2324
import org.springframework.beans.factory.support.RootBeanDefinition;
2425
import org.springframework.beans.factory.xml.BeanDefinitionParser;
@@ -46,14 +47,18 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
4647
if (this.handlerAdapterBeanName == null) {
4748
RootBeanDefinition handlerAdapterDef = new RootBeanDefinition(SimpleControllerHandlerAdapter.class);
4849
handlerAdapterDef.setSource(source);
50+
handlerAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
4951
this.handlerAdapterBeanName = parserContext.getReaderContext().registerWithGeneratedName(handlerAdapterDef);
52+
parserContext.registerComponent(new BeanComponentDefinition(handlerAdapterDef, handlerAdapterBeanName));
5053
}
5154
RootBeanDefinition handlerMappingDef;
5255
if (this.handlerMappingBeanName == null) {
5356
handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
5457
handlerMappingDef.setSource(source);
5558
handlerMappingDef.getPropertyValues().add("order", "1");
56-
this.handlerMappingBeanName = parserContext.getReaderContext().registerWithGeneratedName(handlerMappingDef);
59+
handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
60+
this.handlerMappingBeanName = parserContext.getReaderContext().registerWithGeneratedName(handlerMappingDef);
61+
parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingBeanName));
5762
} else {
5863
handlerMappingDef = (RootBeanDefinition) parserContext.getReaderContext().getRegistry().getBeanDefinition(this.handlerMappingBeanName);
5964
}

0 commit comments

Comments
 (0)