If you are injecting the shopping cart directly into your controller, the issue is likely happening because your controller is singleton scoped (by default), which is wider scope than the bean you're injecting. This excellent article gives an overview of four approaches to exactly what you're trying to do:
[To see links please register here]
.
Here's a quick summary of solutions:
1. Scope the controller to session scope (use `@scope("session")` on controller level) and just have a shopping cart instance in the controller.
2. Scope the controller to request and have session-scoped shopping cart injected.
3. Just use the session directly - kind of messy, IMO.
4. Use Spring's annotation `<aop:scoped-proxy/>`.
All of the methods have their pros and cons. I usually go with option 2 or 4. Option 4 is actually pretty simple and is the only approach I have seen [documented by Spring.](
[To see links please register here]
)