Reputation: 527
In my project I use an HSQLDB instance to serve for unit tests, and I do this by conveniently declaring a <jdbc:embedded-database>
tag as Spring's doc said here.
Now for some reason I'd like to give it multiple names: name="a,b,c"
, just like we usually do on normal Spring beans. However, I found the tag doesn't allow "name" attribute.
Maybe I can workaround this using aliases, but it seems ridiculous to me.
EDIT:
I want to know why Spring doesn't provide "name" for many special tags such as <jdbc:embedded-database>
, <util:list>
, etc.
Upvotes: 0
Views: 59
Reputation: 23893
Your idea is not a workaround and not ridiculous at all. In fact Spring parses the name of a bean definition separating it using comma as separator and create an alias internally for each "name".
If you open the source code of org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(Element, ParserContext)
, you will see this on line 69:
String[] aliases = new String[0];
String name = element.getAttribute(NAME_ATTRIBUTE);
if (StringUtils.hasLength(name)) {
aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
}
BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
that is what you suggested from the beginning.
Upvotes: 1