diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java index aa9bbe94e8..f56f0e527a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -150,8 +150,8 @@ public class BeanDefinitionReaderUtils { // Register aliases for bean name, if any. String[] aliases = definitionHolder.getAliases(); if (aliases != null) { - for (String aliase : aliases) { - registry.registerAlias(beanName, aliase); + for (String alias : aliases) { + registry.registerAlias(beanName, alias); } } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java index 38dba2c10e..ad6c6e2f2e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,12 +49,13 @@ import org.springframework.util.StringUtils; */ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionParser { - /** Constant for the id attribute */ + /** Constant for the "id" attribute */ public static final String ID_ATTRIBUTE = "id"; - /** Constant for the name attribute */ + /** Constant for the "name" attribute */ public static final String NAME_ATTRIBUTE = "name"; + @Override public final BeanDefinition parse(Element element, ParserContext parserContext) { AbstractBeanDefinition definition = parseInternal(element, parserContext); @@ -66,10 +67,12 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars "Id is required for element '" + parserContext.getDelegate().getLocalName(element) + "' when used as a top-level tag", element); } - String[] aliases = new String[0]; - String name = element.getAttribute(NAME_ATTRIBUTE); - if (StringUtils.hasLength(name)) { - aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name)); + String[] aliases = null; + if (shouldParseNameAsAliases()) { + String name = element.getAttribute(NAME_ATTRIBUTE); + if (StringUtils.hasLength(name)) { + aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name)); + } } BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases); registerBeanDefinition(holder, parserContext.getRegistry()); @@ -170,7 +173,18 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars } /** - * Controls whether this parser is supposed to fire a + * Determine whether the element's "name" attribute should get parsed as + * bean definition aliases, i.e. alternative bean definition names. + *

The default implementation returns {@code true}. + * @return whether the parser should evaluate the "name" attribute as aliases + * @since 4.1.5 + */ + protected boolean shouldParseNameAsAliases() { + return true; + } + + /** + * Determine whether this parser is supposed to fire a * {@link org.springframework.beans.factory.parsing.BeanComponentDefinition} * event after parsing the bean definition. *

This implementation returns {@code true} by default; that is,