天天看點

spring的配置檔案中bean的注入方式

2010-06-10 14:31:13

spring的配置檔案中bean的注入方式:

  構造器注入:a:要在注入的類裡提供相應的構造方法;

              b:配置檔案中即為:(簡單屬性的注入)<constructor-arg index=" " value=" "><constructor-arg>

           (引用類型屬性的注入) <constructor-arg ref= " "><constructor-arg>

  setter注入:

      不是簡單屬性(對象)要使用引用的方式注入:<property name=" " ref=" "></property>

    <ref bean="someBean"/> bean的範圍被放大,不單單隻是所在的配置檔案,指的是容器中所有的配置檔案。

繼續閱讀