@Component
@Scope{
Value=WebApplicationContext.SCOPE_SISSION,
proxyMode=ScopeProxyMode.INTERFACES}
Public ShoppingCart cart(){
}
@Component
public class StoreService{
@Autowired
public void setShoppingCart(ShoppingCart shoppingCart){
this.shoppingCart=shoppingCart;
}
}
複製代碼
註解方式:經過使用@Scope當中的proxyMode方式進行代理處理,session
實現了接口的類this
@Scope(value = WebApplicationContext.SCOPE_SESSION,
proxyMode = ScopedProxyMode.INTERFACES)
複製代碼
具體的類可使用CGLib來爲其生成一個代理spa
@Scope(value = WebApplicationContext.SCOPE_SESSION,
proxyMode = ScopedProxyMode.TARGET_CLASS)
複製代碼
可能出現的exception:Scope ‘session’ is not active for the current thread錯誤。代理