亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

4.1節當中我將Scope改成了prototype,為啥返回的還是同一對象?

package?com.imooc.test.beanannotation;

import?org.junit.Test;
import?org.junit.runner.RunWith;
import?org.junit.runners.BlockJUnit4ClassRunner;

import?com.imooc.beanannotation.BeanAnnotation;
import?com.imooc.test.base.UnitTestBase;

@RunWith(BlockJUnit4ClassRunner.class)
public?class?TestBeanAnnotation?extends?UnitTestBase?{
	
	public?TestBeanAnnotation()?{
		super("classpath*:spring-beanannotation.xml");
	}
	
	
	@Test
	public?void?testScpoe()?{
		BeanAnnotation?bean?=?super.getBean("beanAnnotation");
		bean.myHashCode();
		
		bean?=?super.getBean("beanAnnotation");
		bean.myHashCode();
	}
	
}
package?com.imooc.beanannotation;

import?org.springframework.context.annotation.Scope;
import?org.springframework.stereotype.Component;

//@Component("bean")
@Scope("prototype")
@Component
public?class?BeanAnnotation?{
	public?void?myHashCode()?{
		System.out.println("BeanAnnotation?:?"?+?this.hashCode());
	}
	
}

兩個bean輸出的hashcode是一樣的

BeanAnnotation?:?2039473569
BeanAnnotation?:?2039473569

正在回答

1 回答

應該是對一個store子類@scope(value)吧

0 回復 有任何疑惑可以回復我~
#1

星辰Iron 提問者

已經解決了,我把程序關閉重新啟動一下就可以了,估計是緩存的問題。
2017-09-10 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

4.1節當中我將Scope改成了prototype,為啥返回的還是同一對象?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號