我的spring学习笔记7-Spring的Bean配置文件给Bean定义别名
本文介绍如何给Spring的Bean配置文件的Bean定义别名?
原始的
<bean id="business" name="code"><bean id="writer" alias="writerAlias" /><alias name="writer" alias="writerAlias2" />
<bean id="writer" alias="writer1" /> <alias name="writer" alias="writer2" /> <alias name="writer" alias="writer3" /> <alias name="writer3" alias="writer4" /> <alias name="writer4" alias="writer5" /> <alias name="writer5" alias="writer6" /> <alias name="writer6" alias="writer7" />
String [] aliasStrArr = context.getAliases("writer7"); String s = ""; for (int i = 0; i < aliasStrArr.length; i++) { s += aliasStrArr[i] + " - "; } System.out.println(s);String [] aliasStrArr = context.getAliases("writer2"); String s = ""; for (int i = 0; i < aliasStrArr.length; i++) { s += aliasStrArr[i] + " - "; } System.out.println(s);String [] aliasStrArr = context.getAliases("writer"); String s = ""; for (int i = 0; i < aliasStrArr.length; i++) { s += aliasStrArr[i] + " - "; } System.out.println(s);/*** Return the aliases for the given bean name, if any.* All of those aliases point to the same bean when used in a {@link #getBean} call.* <p>If the given name is an alias, the corresponding original bean name* and other aliases (if any) will be returned, with the original bean name* being the first element in the array.* <p>Will ask the parent factory if the bean cannot be found in this factory instance.* @param name the bean name to check for aliases* @return the aliases, or an empty array if none* @see #getBean*/