user7957188
user7957188

Reputation:

How to apply Spring AOP in individual methods

Actually i am working in a Spring MVC project and i successfully applied and configured Spring AOP in my project but i want to apply Spring AOP on individual methods like which method i want to check its working or not.

Its my Aspect code:

   @Pointcut("execution(* com.xyz.dao..*.*(..))")
    public void generalPointCut() {

   }
   @Before("generalPointCut()")
   public void logBefore(JoinPoint joinpoint) {
    Object clazz = joinpoint.getTarget().getClass().getName();
    String methodName = joinpoint.getSignature().getName();
    log.info("Entring in Method" + methodName + " in Calss " + clazz);
}

Upvotes: 0

Views: 737

Answers (1)

dimitrisli
dimitrisli

Reputation: 21381

(followup after comment)

You can be as precise as you want in the Pointcut execution expression. For instance if you wanted to be super specific in terms of the method name including return type and args signature it would look like this:

@Pointcut("execution(public String com.xyz.dao.findMyEntity(Long))")

Take a look at the execution pointcut expression examples in the Spring Documetation.

What you have already is intercepting all methods/classes within the com.xyz.dao package and subpackages, by using * as a wildcard.

As you'll see in the examples you can drill down to the method name level.

Upvotes: 1

Related Questions