我使用了@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());
? ?}
}
輸出了兩個同樣的hashcode。
2017-06-16
@Scope(scopeName="prototype") 這行代碼修改成@Scope("prototype")即可
2018-08-24
在一個類中,通過多次訪問這個對象的時候,HashCode總是一樣的,但是如果在兩個類中一用這個對象,然后分別這兩個類中的引用
2018-06-15
不是應(yīng)該用
么?
2017-09-03
輸出的是store.getClass().hashCode(),要store.hashCode()才會不一樣
2017-08-07
為什么 》???
2017-06-16
是我最后寫錯了!基礎(chǔ)知識不扎實,╮(╯▽╰)╭