私のXML構成では、これがあります:
<bean id="soap" class="org.grocery.item.Soap" scope="prototype">
<property name="price" value="20.00" />
</bean>
そして、私のサービスクラスでは、「soap」を次のように自動配線しています。
@Autowired
private Soap soap;
//Accessor methods
そして、次のようなテストクラスを作成しました:
Item soap = service.getItem(ITEM.SOAP);
Item soap2 = service.getItem(ITEM.SOAP);
if(soap2 == soap ){
System.out.println("SAME REFERENCE");
}
そして、これは私のサービス クラスの getItem メソッドです。
public Item item(Item enumSelector) {
switch (enumSelector) {
case SOAP:
return this.getSoap();
}
return null;
}
@Autowired
private Soap soap;
//Accessor methods
今私が期待しているのは、 this.getSoap(); を呼び出すときです。新しい SOAP オブジェクトを返します。ただし、soap のスコープがプロトタイプとして宣言されているにもかかわらず、そうではありませんでした。何故ですか?