2 回答

小怪獸愛吃肉
TA貢獻(xiàn)1852條經(jīng)驗 獲得超1個贊
當(dāng)然不一樣。我今天在做springbatch的 job時遇到了同樣的問題,到谷歌搜了一下:
A bean with scope prototype just means that everytimeApplicationContext.getBean is called a new instance of the bean is created. If you try to inject a prototype bean in a singleton, your prototype bean will be injected once (and so is no more a prototype).
大意就是說spring管理的bean默認(rèn)是單例模式,這種情況下autowired和getbean拿到的沒區(qū)別,但是如果你加入了@Scope(SCOPE_PROTOTYPE)那么就必須用getbean去拿否則這個注解沒有任何意義
添加回答
舉報
0/150
提交
取消