Skip to content

Commit 901d7d0

Browse files
committed
AbstractBeanDefinitionParser allows for skipping evaluation of XML "name" attribute
Issue: SPR-12643 (cherry picked from commit 11bf3b3)
1 parent bfba988 commit 901d7d0

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -150,8 +150,8 @@ public static void registerBeanDefinition(
150150
// Register aliases for bean name, if any.
151151
String[] aliases = definitionHolder.getAliases();
152152
if (aliases != null) {
153-
for (String aliase : aliases) {
154-
registry.registerAlias(beanName, aliase);
153+
for (String alias : aliases) {
154+
registry.registerAlias(beanName, alias);
155155
}
156156
}
157157
}

spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,12 +49,13 @@
4949
*/
5050
public abstract class AbstractBeanDefinitionParser implements BeanDefinitionParser {
5151

52-
/** Constant for the id attribute */
52+
/** Constant for the "id" attribute */
5353
public static final String ID_ATTRIBUTE = "id";
5454

55-
/** Constant for the name attribute */
55+
/** Constant for the "name" attribute */
5656
public static final String NAME_ATTRIBUTE = "name";
5757

58+
5859
@Override
5960
public final BeanDefinition parse(Element element, ParserContext parserContext) {
6061
AbstractBeanDefinition definition = parseInternal(element, parserContext);
@@ -66,10 +67,12 @@ public final BeanDefinition parse(Element element, ParserContext parserContext)
6667
"Id is required for element '" + parserContext.getDelegate().getLocalName(element)
6768
+ "' when used as a top-level tag", element);
6869
}
69-
String[] aliases = new String[0];
70-
String name = element.getAttribute(NAME_ATTRIBUTE);
71-
if (StringUtils.hasLength(name)) {
72-
aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
70+
String[] aliases = null;
71+
if (shouldParseNameAsAliases()) {
72+
String name = element.getAttribute(NAME_ATTRIBUTE);
73+
if (StringUtils.hasLength(name)) {
74+
aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
75+
}
7376
}
7477
BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
7578
registerBeanDefinition(holder, parserContext.getRegistry());
@@ -170,7 +173,18 @@ protected boolean shouldGenerateIdAsFallback() {
170173
}
171174

172175
/**
173-
* Controls whether this parser is supposed to fire a
176+
* Determine whether the element's "name" attribute should get parsed as
177+
* bean definition aliases, i.e. alternative bean definition names.
178+
* <p>The default implementation returns {@code true}.
179+
* @return whether the parser should evaluate the "name" attribute as aliases
180+
* @since 4.1.5
181+
*/
182+
protected boolean shouldParseNameAsAliases() {
183+
return true;
184+
}
185+
186+
/**
187+
* Determine whether this parser is supposed to fire a
174188
* {@link org.springframework.beans.factory.parsing.BeanComponentDefinition}
175189
* event after parsing the bean definition.
176190
* <p>This implementation returns {@code true} by default; that is,

0 commit comments

Comments
 (0)