在spring中會有如下的幾種情況:
1.在當前容器中,(即在spring.xml這一個配置文件中),一個bean引用了另一個bean。
使用
1》 <ref bean="另一個bean的id" />
1.1 構造器
1.2 setter
2》ref作屬性
-----2.1 -構造器注入:<constructor-arg index="0" ref="另一個bean的id" />
-----2.2-setter注入:<property name=" " ref="另一個bean的id" />
2.<ref local=" ">
引用當前容器中的另一個<bean>,只能通過引用這樣定義的<bean>即:<bean id="bean1" class=""/> 定義id的可以被識別.
其餘的<bean name="bean2" class=""> 或者<bean alias="bean3" class="">都識別不到。
3.<ref parent="" />
引用父容器中的bean,若父容器中定義的<bean id="bean1" class="" />,當前容器中也有一個<bean id="bean1" class=""/> 則<ref parent ="">會直接去父容器中去找,如果沒有那就是沒有,不會在當前容器中尋找。
4.內部bean
即
1.在<property>或<constructor-arg>內部通過<bean>定義的,
2.該bean不管是否指定id或者name,該bean都有一個唯一的匿名標識符,且不能被指定別名
3.該bean隊其他外部的bean不可見。