在spring容器管理的Bean中,必须仅且只有一个无重复的ID。spring
通常状况下,配置一个bean时,须要指定它的ID属性做为bean的名称。spa
<bean id="hello" class="com.learnSpring.hellWorld"/> 用户能够经过getBean(“hello”)获取hello 的Beancode
若是在配置bean的时候并无声明ID属性,则采用全类限定名做为bean的ID。<bean class="com.learnSpring.hellWorld"/> 即此时的id为com.learnSpring.hellWorldget
用户能够经过getBean(“com.learnSpring.hellWorld”)获取com.learnSpring.hellWorld的Beanstring
若是存在多个class属性都是同样的匿名的Bean,则生成的ID根据spring读取配置文件的顺序生成IDit
若是一个bean只配置了name属性,可是没有配置ID属性,默认会ID属性=name属性
eg:<bean name="hello" class="com.learnSpring.hellWorld"/>class
name定义的是bean的alias,能够有多个,并可能与其余的bean重名。容器
在实际命名中,通常采起id属性指定惟一的名称。配置