(1) Overview & (2) Configure
(3) Example
In APO, some process called BEFORE specified point (Point cut). The typical example is a LOGGING. This example also does logging. The logging method called BEFORE the point cut (Before Advise).
To implements Before Advise, AspectJ provides @Before annotation:
In the line 16:
3.1. The first asterisk specified ANY return type
3.2. The second asterisk specified ANY method (name) in this class
3.3. The two period “..” specified ANY number and type of method parameter
In the line 23:
3.4. The pointed asterisk specified ANY method name starts from “goTo”
In the line 30:
3.5. The method name is specified as “initList”
package com.ns.spring.aop.advise; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @Aspect @Component public class AspectBefore { private static final Logger log = LoggerFactory.getLogger(AspectBefore.class); @Before("execution(* com.ns.spring.RmaController.*(..))") public void beforeAllRmaCtrl(JoinPoint pt){ log.info("\n:::::::::::::::: Controller :::::::::::::::: " +pt.getSignature().getName() + " called!"); Object[] arr = pt.getArgs(); logMsg(arr); } @Before("execution(* com.ns.spring.RmaController.goTo*(..))") public void beforeAllRmaCtrlGoTo(JoinPoint pt){ log.info("\n................ Controller (Screen Transition) ................ " +pt.getSignature().getName() + " called!"); Object[] arr = pt.getArgs(); logMsg(arr); } @Before("execution(* com.ns.spring.RmaController.initList(..))") public void beforeRmaCtrl_initList(JoinPoint pt){ log.info("\n***************** Controller (Specified Method) ***************** " +pt.getSignature().getName() + " called!"); Object[] arr = pt.getArgs(); logMsg(arr); } private void logMsg(Object[] arr) { if( arr != null && arr.length > 0 ) { for( Object obj: arr) { log.info("Parameter value -> "+obj.toString()); } } } }