Spring Proxy Mode



@Component
@Scope(

value=WebApplicationContext.SCOPE_SESSION,
proxyMode=ScopedProxyMode.INTERFACES)
public MyShopCart cart() { ... }


@Component
public class MyStore {
@Autowired

public void setMyShopCart(MyShopCart myShopCart) {
            this.myShopCart = myShopCart;
}
}


Here, when the spring application context is prepared then the Object of MyShopCart is not created because it is to be created when a session will be created in the Application.

So, here for the MyStore class the MyShopCart actual bean will not be created by spring because yet no session exist.
But, here spring will inject proxy for the MyShopCart bean in the MyStore setMyShopCart method.

proxyMode is set to ScopedProxyMode.INTERFACES, it says that the proxy should implement the MyShopCart interface and delegate to the implementation of the bean.

But if MyShopCart is not an Interface then you need to use CGLib to generate a class-based
proxy. Therefore, if the bean type is a concrete class, you need to set proxyMode to ScopedProxy-
Mode.TARGET_CLASS.

XML Declaration with Proxy Class
<bean id="cart"
class="com.app.MyShopCart"
scope="session">
<aop:scoped-proxy />
</bean> 

By default it uses CGLIB to create a target proxy class.

XML Declaration with Proxy Interface
<bean id="cart"
class="com.myapp.ShoppingCart"
scope="session">
<aop:scoped-proxy proxy-target-class="false" />
</bean> 


You need to add below namespace in the config XML file
xmlns:aop="http://www.springframework.org/schema/aop"