some minor adjustments to the mvc namespace to make it work in the tools
This commit is contained in:
parent
14b69148f9
commit
7c6c1c3ad8
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package org.springframework.web.servlet.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
|
|
@ -40,6 +38,7 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
|||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
|
||||
import org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* {@link BeanDefinitionParser} that parses the {@code annotation-driven} element to configure a Spring MVC web
|
||||
|
|
@ -85,24 +84,28 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
|
|||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
Object source = parserContext.extractSource(element);
|
||||
|
||||
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
|
||||
parserContext.pushContainingComponent(compDefinition);
|
||||
|
||||
RootBeanDefinition annMappingDef = new RootBeanDefinition(DefaultAnnotationHandlerMapping.class);
|
||||
annMappingDef.setSource(source);
|
||||
annMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
annMappingDef.getPropertyValues().add("order", 0);
|
||||
String annMappingName = parserContext.getReaderContext().registerWithGeneratedName(annMappingDef);
|
||||
|
||||
RootBeanDefinition bindingDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
|
||||
bindingDef.setSource(source);
|
||||
bindingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
bindingDef.getPropertyValues().add("conversionService", getConversionService(element, source, parserContext));
|
||||
bindingDef.getPropertyValues().add("validator", getValidator(element, source, parserContext));
|
||||
|
||||
RootBeanDefinition annAdapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
|
||||
annAdapterDef.setSource(source);
|
||||
annAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
annAdapterDef.getPropertyValues().add("webBindingInitializer", bindingDef);
|
||||
annAdapterDef.getPropertyValues().add("messageConverters", getMessageConverters(source));
|
||||
String adapterName = parserContext.getReaderContext().registerWithGeneratedName(annAdapterDef);
|
||||
|
||||
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
|
||||
parserContext.pushContainingComponent(compDefinition);
|
||||
|
||||
parserContext.registerComponent(new BeanComponentDefinition(annMappingDef, annMappingName));
|
||||
parserContext.registerComponent(new BeanComponentDefinition(annAdapterDef, adapterName));
|
||||
parserContext.popAndRegisterContainingComponent();
|
||||
|
|
@ -118,7 +121,9 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
|
|||
else {
|
||||
RootBeanDefinition conversionDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
|
||||
conversionDef.setSource(source);
|
||||
conversionDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
String conversionName = parserContext.getReaderContext().registerWithGeneratedName(conversionDef);
|
||||
parserContext.registerComponent(new BeanComponentDefinition(conversionDef, conversionName));
|
||||
return new RuntimeBeanReference(conversionName);
|
||||
}
|
||||
}
|
||||
|
|
@ -130,7 +135,9 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
|
|||
else if (jsr303Present) {
|
||||
RootBeanDefinition validatorDef = new RootBeanDefinition(LocalValidatorFactoryBean.class);
|
||||
validatorDef.setSource(source);
|
||||
validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
String validatorName = parserContext.getReaderContext().registerWithGeneratedName(validatorDef);
|
||||
parserContext.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));
|
||||
return new RuntimeBeanReference(validatorName);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import java.util.List;
|
|||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
|
|
@ -37,10 +39,14 @@ import org.w3c.dom.Element;
|
|||
class InterceptorsBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
|
||||
parserContext.pushContainingComponent(compDefinition);
|
||||
|
||||
List<Element> interceptors = DomUtils.getChildElementsByTagName(element, new String[] { "bean", "interceptor" });
|
||||
for (Element interceptor : interceptors) {
|
||||
RootBeanDefinition mappedInterceptorDef = new RootBeanDefinition(MappedInterceptor.class);
|
||||
mappedInterceptorDef.setSource(parserContext.extractSource(interceptor));
|
||||
mappedInterceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
String[] pathPatterns;
|
||||
BeanDefinitionHolder interceptorDef;
|
||||
if ("interceptor".equals(interceptor.getLocalName())) {
|
||||
|
|
@ -59,8 +65,11 @@ class InterceptorsBeanDefinitionParser implements BeanDefinitionParser {
|
|||
}
|
||||
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, pathPatterns);
|
||||
mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, interceptorDef);
|
||||
parserContext.getReaderContext().registerWithGeneratedName(mappedInterceptorDef);
|
||||
String mappedInterceptorName = parserContext.getReaderContext().registerWithGeneratedName(mappedInterceptorDef);
|
||||
parserContext.registerComponent(new BeanComponentDefinition(mappedInterceptorDef, mappedInterceptorName));
|
||||
}
|
||||
|
||||
parserContext.popAndRegisterContainingComponent();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.springframework.web.servlet.config;
|
|||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
|
|
@ -46,14 +47,18 @@ class ViewControllerBeanDefinitionParser implements BeanDefinitionParser {
|
|||
if (this.handlerAdapterBeanName == null) {
|
||||
RootBeanDefinition handlerAdapterDef = new RootBeanDefinition(SimpleControllerHandlerAdapter.class);
|
||||
handlerAdapterDef.setSource(source);
|
||||
handlerAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
this.handlerAdapterBeanName = parserContext.getReaderContext().registerWithGeneratedName(handlerAdapterDef);
|
||||
parserContext.registerComponent(new BeanComponentDefinition(handlerAdapterDef, handlerAdapterBeanName));
|
||||
}
|
||||
RootBeanDefinition handlerMappingDef;
|
||||
if (this.handlerMappingBeanName == null) {
|
||||
handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
|
||||
handlerMappingDef.setSource(source);
|
||||
handlerMappingDef.getPropertyValues().add("order", "1");
|
||||
this.handlerMappingBeanName = parserContext.getReaderContext().registerWithGeneratedName(handlerMappingDef);
|
||||
handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
this.handlerMappingBeanName = parserContext.getReaderContext().registerWithGeneratedName(handlerMappingDef);
|
||||
parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingBeanName));
|
||||
} else {
|
||||
handlerMappingDef = (RootBeanDefinition) parserContext.getReaderContext().getRegistry().getBeanDefinition(this.handlerMappingBeanName);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue