我使用了@Scope(“prototype”),為什么測試結(jié)果還是單例的
@Bean
@Scope(scopeName="prototype")
public Store stringStore(){
? ?return ?new StringStore();
}
@Test
public void test12() {
? ?for(int i=0;i<2;i++){
? ? ? ?StringStore store = super.getBean("stringStore");
? ? ? ?System.out.println(store.getClass().hashCode());
? ?}
}
輸出了兩個(gè)同樣的hashcode。
2017-06-16
@Scope(scopeName="prototype") 這行代碼修改成@Scope("prototype")即可
2018-08-24
在一個(gè)類中,通過多次訪問這個(gè)對(duì)象的時(shí)候,HashCode總是一樣的,但是如果在兩個(gè)類中一用這個(gè)對(duì)象,然后分別這兩個(gè)類中的引用
2018-06-15
不是應(yīng)該用
么?
2017-09-03
輸出的是store.getClass().hashCode(),要store.hashCode()才會(huì)不一樣
2017-08-07
為什么 》???
2017-06-16
是我最后寫錯(cuò)了!基礎(chǔ)知識(shí)不扎實(shí),╮(╯▽╰)╭