Search code examples
javaspringaopspring-aop

Spring AOP Pointcut with method name starting with get


I'm trying to implement a Pointcut for spring AOP. All the methods which are like getXXXX should be logged. I tried the following but either they throw exception or does not trigger:

1st try

@Pointcut("within(net.services.*.get*)")
private void clServiceLayer() {}

@Pointcut("within(net.services.*.get*(..))")
private void clServiceLayer() {}

Need help with the proper expression for point cut.


Solution

  • within limits matching to join points within certain types. Instead you should use execution Pointcut Designator for matching method execution join points:

    @Pointcut("execution(* net.tds.adm.metasolv.customerlink.services.*.get*(..))")
    

    Checkout the Spring Documentation for more detailed discussion.