@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错误。代理