1. 程式人生 > >spring 自動裝配bean

spring 自動裝配bean

  • no – 預設情況下,自動配置是通過“ref”屬性手動設定
  • <bean id="customer" class="com.yiibai.common.Customer" autowire="">
        <property name="person" ref="person" />
    </bean>
    <bean id="person" class="com.yiibai.common.Person" />
  • byName – 根據屬性名稱自動裝配。如果一個bean的名稱和其他bean屬性的名稱是一樣的,將會自裝配它。
    <bean id="customer" class="com.yiibai.common.Customer" autowire="byName" />	
    <bean id="person" class="com.yiibai.common.Person" />
  • byType – 按資料型別自動裝配。如果一個bean的資料型別是用其它bean屬性的資料型別,相容並自動裝配它。
    <bean id="customer" class="com.yiibai.common.Customer" autowire="byType" />
    <bean id="person" class="com.yiibai.common.Person" />
  • constructor – 在建構函式引數的byType方式。
  • <bean id="customer" class="com.yiibai.common.Customer" autowire="constructor" />
    	
    <bean id="person" class="com.yiibai.common.Person" />
  • autodetect – 如果找到預設的建構函式,使用“自動裝配用構造”; 否則,使用“按型別自動裝配”。