import java.util.Arrays;
import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class ServiceInterceptor {
private Logger log = Logger.getLogger(this.getClass());
@Before("execution(* es.agilismo.pruebas.service.*.*(..))")
public void beforeInvoke(JoinPoint jp) throws Throwable {
if ( log.isDebugEnabled() ) {
log.debug("Before "+claseALaQueLlamamos(jp)+" calling "+metodoAlQueLlamamos(jp)+" with args "+argumentos(jp));
}
}
private String metodoAlQueLlamamos(JoinPoint jp) {
return jp.getSignature().getName();
}
private String claseALaQueLlamamos(JoinPoint jp) {
return ""+jp.getTarget().getClass();
}
private String argumentos(JoinPoint jp) {
return ""+Arrays.asList(jp.getArgs());
}
}
Además, en el applicationContext.xml he tenido que poner:
<aop:aspectj-autoproxy />
declarando por supuesto el espacio de nombres xmlns:aop dejando la cabecera algo así como:
<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="
Espero les resulte útil.
PS
¿Para cuándo GMail incorporará algo como Snipt.org? ;-)