Running the application..
Build this application and deploy it to Tomcat.
Then point your browser to:
http://localhost:8080/HelloWorld/shop
You will see the number of items in the Shopping cart.
Each time you refresh your browser, the count will increase by 1.
Now point your browser to:
http://localhost:8080/HelloWorld/checkout
You will see the exact same items count in the Checkout cart.
Thanks to Spring dependency injection, both the Shop and Checkout are seeing the same Cart.
Imagine if we had more modules in our application - Shipping.java, Audit.java, NotificationEmail.java, FeedbackRequest.java etc which all needed to use the cart. We could ask Spring to inject the same cart in each of these modules. This will ensure that they are all looking at the exact same cart.
No comments:
Post a Comment