javaspringaopaspect

Pointcut referring to all methods with name starting by


I was trying to implement an easy pointcut expression inside my code, this is my Aspect class

@Aspect
public class PaymentAspect {
    
    @Autowired
    private OrdineService ordineService;
    
    @Pointcut("execution(* *..createPayment*(..))")  
    public void toVerifyCart() {} 
      
    @Before("toVerifyCart()")
    public void validateCart(JoinPoint jp) throws ServiceException, TokenStreamException {
    
         //Instructions...
    }
}

And this is the one of the methods before which I would like to call the validateCart() method...

public String createPayment(@RequestData(paramaterName = "httpRequest") Long cartID,
        String currency, String appContext, 
        @RequestData(paramaterName = "httpRequest") HttpServletRequest request) throws ServiceException;

The only problem is that my code is not calling at all the method... Is there anything I'm getting wrong here?


Solution

  • One important thing which you're missing here is @Configuration. You can have a @Component only for enable the class as a candidate component, but for @Aspect, you better have it annotated with @Configuration.