Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 411
Zeus Avatar asked May 25 '16 22:05

Zeus


People also ask

How do I declare a pointcut in Spring AOP?

In Spring AOP, a join point always represents a method execution. A pointcut is a predicate that matches the join points, and the pointcut expression language is a way of describing pointcuts programmatically.

Which method is executed first in AOP?

Executing method on the target class Thus, Spring AOP injects a proxy instead of an actual instance of the target class. When we start the Spring or Spring Boot application, we see Spring executes the advice before the actual method.

How do I get method parameters in AOP?

You have a few options: First, you can use the JoinPoint#getArgs() method which returns an Object[] containing all the arguments of the advised method. You might have to do some casting depending on what you want to do with them.

What methods does this pointcut expression reference?

Pointcut is an expression language of spring AOP which is basically used to match the target methods to apply the advice. It has two parts ,one is the method signature comprising of method name and parameters. Other one is the pointcut expression which determines exactly which method we are applying the advice to.


Video Answer


1 Answers

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.

like image 64
Ali Dehghani Avatar answered Oct 30 '22 23:10

Ali Dehghani