Spring中Bean的命名
1、每個Bean可以有一個id屬性,並可以根據該id在IoC容器中查找該Bean,該id屬性值必須在IoC容器中唯一;
2、可以不指定id屬性,只指定全限定類名,如:
<bean class="com.zyh.spring3.hello.StaticBeanFactory"></bean>
此時需要通過接口getBean(Class<T> requiredType)來獲取Bean;
如果該Bean找不到則拋異常:NoSuchBeanDefinitionException
如果該類型的Bean有多個則拋異常:NoUniqueBeanDefinitionException
3、如果不指定id,只指定name,那麼name爲Bean的標識符,並且需要在容器中唯一;
4、同時指定name和id,此時id爲標識符,而name爲Bean的別名,兩者都可以找到目標Bean;