豆のスプリング(D)と単一のマルチインスタンスの順序を作成します

変更オーダーを作成します。

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="person1" class="helloWorld.Person"></bean>
    <bean id="car1" class="helloWorld.Car"></bean>
    <bean id="book1" class="helloWorld.Book"></bean>
</beans>

追加した場合、オーダーを作成すると、依存-のプロパティ、作成順にあります

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="person1" class="helloWorld.Person" depend-on="car1,book1"></bean>
    <bean id="car1" class="helloWorld.Car"></bean>
    <bean id="book1" class="helloWorld.Book"></bean>
</beans>

だから、今回は順番は車、本、人であります

デフォルトの単一のインスタンスを変更

あなたがする方法をマルチインスタンスを変更したい場合は、デフォルトでは、単一のBeanインスタンスを作成するのですか?

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="car1" class="helloWorld.Car" scope="prototype"></bean>
</beans>

それはどこスコープ属性です。

  • プロトタイプは:マルチインスタンスに代わって、新しいオブジェクト毎回getBeanメソッド呼び出しを作成します。
  • シングルトン:容器は各コールgetBean参照メソッドのオブジェクトを返すように作成されたときにオブジェクトの単一のインスタンスが作成され表します。
公開された49元の記事 ウォンの賞賛1 ビュー930

おすすめ

転載: blog.csdn.net/qq_38783257/article/details/104270349