AbstractBeanDefinitionParser allows for skipping evaluation of XML "name" attribute
Issue: SPR-12643
This commit is contained in:
parent
d4dac250a8
commit
11bf3b3524
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
* <p>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.
|
||||
* <p>This implementation returns {@code true} by default; that is,
|
||||
|
|
Loading…
Reference in New Issue