errors are:
at com.ampta.central_shops.service.cart.CartService.initializeNewCart(CartService.java:53) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355) ~[spring-aop-6.1.13.jar:6.1.13]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:716) ~[spring-aop-6.1.13.jar:6.1.13]
at com.ampta.central_shops.service.cart.CartService$$SpringCGLIB$$0.initializeNewCart() ~[classes/:na]
at com.ampta.central_shops.controller.CartItemController.addItemToCart(CartItemController.java:32) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
@PostMapping("/item/add")
public ResponseEntity addItemToCart(@RequestParam(required = false) Long cartId,
@RequestParam Long productId,
@RequestParam Integer quantity){
try {
Hey, in this code there is no auto initialize cart for default users so you can set the userid manually or integrate spring security. It will be solution for your problem.
bold part is not working in my system
errors are: at com.ampta.central_shops.service.cart.CartService.initializeNewCart(CartService.java:53) ~[classes/:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355) ~[spring-aop-6.1.13.jar:6.1.13] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:716) ~[spring-aop-6.1.13.jar:6.1.13] at com.ampta.central_shops.service.cart.CartService$$SpringCGLIB$$0.initializeNewCart() ~[classes/:na]
at com.ampta.central_shops.controller.CartItemController.addItemToCart(CartItemController.java:32) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
@PostMapping("/item/add") public ResponseEntity addItemToCart(@RequestParam(required = false) Long cartId,
@RequestParam Long productId,
@RequestParam Integer quantity){
try {